vue中監聽頁面是否有回車鍵按下


一般來說,如果你只是input密碼輸入框,那就監聽keyup事件,外加上.enter修飾符,如果是使用的第三方組件庫,就在加上一個加上.native修飾符,如下

<el-input placeholder="請輸入密碼" v-model="ruleForm.userpassword" @keyup.enter.native="submitForm('ruleForm')"></el-input>
<input v-model="ruleForm.userpassword" placeholder="請輸入密碼" @keyup.enter="submitForm('ruleForm')">
submitForm(formName) {
   this.$refs[formName].validate((valid) => {
     if (valid) {
        alert('submit!');
     } else {
      console.log('error submit!!');
      return false;
     }
})
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM