官方暴露的事件中貌似没有enter事件,然后直接在el-input上写@keyup.enter也没能捕抓到事件,望大神赐教~~
<el-input type="password" v-model="loginForm.password" placeholder="密码" @keyup.enter.native="loginSubmit"></el-input>
@keyup.enter.native就可以触发了
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link href="http://cdn.bootcss.com/element-ui/1.2.7/theme-default/index.css" rel="stylesheet" />
</head>
<body>
<div id="app">
<el-input v-model="input" v-enter @enter.native="log" placeholder="请输入内容"></el-input>
</div>
<script src="http://cdn.bootcss.com/vue/2.1.0/vue.min.js"></script>
<script src="http://cdn.bootcss.com/element-ui/1.2.7/index.js"></script>
<script>
Vue.directive('enter', {
bind: function (el, binding, vnode) {
const input = el.getElementsByTagName('input')[0];
input.addEventListener('keypress', function (e) {
var key = e.which || e.keyCode;
if (key === 13) { // 13 is enter
// code for enter
el.dispatchEvent(new Event('enter'))
}
})
},
unbind: function (el, binding, vnode) {
}
})
new Vue({
el: '#app',
data() {
return {
input: null
}
},
methods: {
log() {
console.log(this.input)
}
}
})
</script>
</body>
</html>
6 回答3.1k 阅读✓ 已解决
8 回答4.9k 阅读✓ 已解决
6 回答3.6k 阅读✓ 已解决
5 回答2.9k 阅读✓ 已解决
6 回答2.5k 阅读
5 回答6.5k 阅读✓ 已解决
4 回答2.3k 阅读✓ 已解决
@keyup.enter.native