首页 > 解决方案 > AlpineJs 不会更新绑定属性

问题描述

我想在 keydown 上更新属性绑定(x 模型)属性。

但它根本不起作用。

我这里有什么问题吗?

链接到 jsfiddle

<div x-data="app()" class="w-64">
   <input x-ref="textInput" x-model="textInput" x-on:keyup="limitInput($el)" type="text">
</div>


function app() { 
  return {
    textInput: '',
    limitInput($el) {
       this.textinput =  ''
    },
   }
}

标签: javascriptalpine.js

解决方案


您正在使用这种方式input将 0的长度限制在. 另外,你想用这个功能做什么?因为调用它会在按下按键更新输入之前调用它,如果你想在之后调用它,请使用.maxlength="0"input
limitInputkeydownkeyup


推荐阅读