vue 中input框的blur事件和enter事件同时使用时,触发enter事件时blur事件也会被触发的方法解决


vue 中input框的blur事件和enter事件同时使用时,触发enter事件时blur事件也会被触发的方法解决


1
<template> 2 <input :value="val" @blur="handleBlur($event,参数1,参数2)" @keyup.enter.native="handleEnter($event,参数1,参数2)"> 3 </template> 4 <script> 5 export default { 6 data(){ 7 return { 8 isEnter: false 9 } 10 }, 11 method:{ 12 handleBlur(event,参数1,参数2){ 13 //如果回车和blur事件的代码是相同的 则不需要使用isEnter进行区分 14 if(this.isEnter) { 15 //...回车事件运行的代码 16   this.isEnter = false 17 }else { 18 // blur事件运行的代码 19 } 20 }, 21 handleEnter(event,参数1,参数2){ 22 this.isEnter = true; 23 event.target.blur(event,参数1,参数2) 24 } 25 } 26 } 27 </script>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM