el-input 无法触发@keyup.enter 解决方法

2,374 阅读1分钟

<el-input placeholder="请输入密码" type="password" v-model="password" @input="checkInput" @keyup.enter="login" clearable></el-input>

替换成

<el-input placeholder="请输入密码" type="password" v-model="password" @input="checkInput" @keyup.enter.native="login" clearable></el-input>

注意:v-model数据层一定要在@keyup.enter 事件之前。

ps: 在 Vue 2.0 中,为自定义组件绑定原生事件必须使用 .native 修饰符,只有Button 组件可以监听 click 事件。