我想在用户按回车键时停止checkingNric的运行。请帮助。
checkingNric
onPress(e){ if(e.keyCode == 13){ this.checkingNric(e.preventDefault()); } },
lskq00tm1#
不知道我是否理解得很好。这将在第一次按下enter后停止调用this.checkingNric()。当您使用Vue时,添加enterWasPressed:将false变量添加到组件的data()。
onPress(e){ if(e.keyCode == 13){ this.enterWasPressed = true; } if (! this.enterWasPressed) { this.checkingNric(e.preventDefault()); } },
lymnna712#
可以使用Vue的关键点修改器,并像keydown.enter.prevent一样将它们链接起来。
keydown.enter.prevent
new Vue({ el: "#app", methods: { myMethod(e) { console.log(123); } } })
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script> <div id="app"> <button @click="myMethod" @keydown.enter.prevent="">Only click, no enter</button> </div>
r9f1avp53#
在将事件作为参数传递之前运行preventDefault:
preventDefault
onPress(e){ if(e.keyCode == 13){ e.preventDefault(); this.checkingNric(e); } },
3条答案
按热度按时间lskq00tm1#
不知道我是否理解得很好。
这将在第一次按下enter后停止调用this.checkingNric()。
当您使用Vue时,添加enterWasPressed:将false变量添加到组件的data()。
lymnna712#
可以使用Vue的关键点修改器,并像
keydown.enter.prevent
一样将它们链接起来。r9f1avp53#
在将事件作为参数传递之前运行
preventDefault
: