1.首先需要知道的是@click和@keyup是不能在一個元素上同時使用的;
2.當我們在項目中引入了第三方組件庫時,發現@keyup.enter沒有作用時,這時改成@keyup.enter.native就可以啦
代碼示例如下:
<div class="login-box"> <div class="form-row"> <div class="label">用戶名:</div> <el-input :autofocus="true" v-model="loginObj.username" placeholder="請輸入用戶名" ></el-input> </div> <div class="form-row"> <div class="label">密碼:</div> <el-input @keyup.enter.native="login" v-model="loginObj.password" placeholder="請輸入密碼"></el-input> </div> <div class="login-btn"> <el-button @click="login">登錄</el-button> </div> </div>