1.第一种情况,input框
<input @keyup.enter="function">
2.在自己封装的组件或者是使用一些第三方的UI库时,会发现并不起效果,这时就需要用到.native
修饰符了
<el-input @keyup.enter.native="function" />
3.如果想要绑定的组件太多,可以对键盘进行监控
mounted() {
// 绑定enter事件
this.enterKeyup();
},
destroyed() {
// 销毁enter事件
this.enterKeyupDestroyed();
},
methods:{
enterKeyupDestroyed() {
document.removeEventListener("keyup", this.keyupHandle);
},
enterKeyup() {
document.addEventListener("keyup", this.keyupHandle);
},
/ 键盘搜索
keyupHandle(e) {
if (e.keyCode === 13) {
this.searchHandle();
}
}
}
本文地址:https://blog.csdn.net/qq_42323925/article/details/107559648
如对本文有疑问, 点击进行留言回复!!
vue 动态设置img的src地址无效,npm run build 后找不到文件的解决
解决vue动态路由异步加载import组件,加载不到module的问题
解决vue的router组件component在import时不能使用变量问题
Vue中的this.$options.data()和this.$data用法说明
GBase 8a MPP Cluster使用Ceph做存储计算分离
网友评论