解决vue中keyup事件和blur重复调用
在keyup触发的事件中解绑失焦函数,在获得焦点focus事件中绑定失焦函数。
<template>
<el-input
v-model="inputVal"
placeholder="请输入内容"
@focus="focusFun"
@blur="triggerBlur&&blurFun()"
@keyup.native.enter="keyupFun"
/>
</template>
<script>
export default {
data() {
return {
inputVal: '',
oldInputValue: '',
triggerBlur: false
}
},
methods: {
focusFun() {
console.log('聚焦')
this.triggerBlur = true
},
blurFun() {
console.log('失焦')
this.inputVal = this.oldInputVal
},
keyupFun() {
console.log('回车')
this.triggerBlur = false
this.oldInputVal = this.inputVal
}
}
}
</script>
解决vue中keyup事件和blur重复调用,触发不同方法