登录页面写提交按钮实现登录,点击回车的方法调用登录方法
<el-button type="primary" @click="onLogin">提交</el-button>
script写登录方法和点击回车方法
methods: {
onLogin() {
this.$router.push('/home');
},
keyDown(e){
e = window.event
if(e.keydown || e.code == 'Enter'){
this.onLogin()
}
}
},
需要写一个监听事件监听回车事件
mounted(){
window.addEventListener('keydown',this.keyDown)
},
destroyed(){
window.removeEventListener('keydown',this.keyDown)
}