General solution:
- Bind the keyup event to the button, and add .native to overwrite the original encapsulated keyup event
<el-button type="primary" class="sub-btn" style="width:100%;" :disabled="btnDisabled" :loading="logining" @click.native.prevent="handleSubmit" @keyup.native.enter="handleSubmit">{
{loginStr}}</el-button>
The ultimate solution:
- The element-ui button is used, because the first case is invalid after binding, record this method. Used in created
created(){
document.onkeyup= e =>{
if (e.keyCode === 13&&e.target.baseURI.match(/login/)) {
this.handleSubmit();//调用登录 验证方法
}
}
}
If there is a good way, you can leave a message