组件中的 Vue 脏状态触发 [英] Vue Dirty state trigering in component
问题描述
我在 Vue 中有一个带有输入字段的页面.当有人更改该组件中的任何输入字段时,我想显示一条消息.我已经习惯了 Angular,您可以在其中使用 isDirty 函数,但 Vue 没有.
有没有办法在 Vue 视图中捕获所有键盘事件?所以我可以捕捉到它并将一个变量设置为 true 以显示消息?
现在我将它添加到所有输入模型中:
有没有办法在 Vue 视图中捕获所有 keyup 事件?
您可以在父容器上绑定单个 onchange
事件并受益于更改事件冒泡的事实:
<input v-model="foo"><input v-model="bar">... 等等.
I have a page in Vue with input fields. I wanna show a message when someone changed any input field in that component. I'm used to Angular where you can use the isDirty function, but Vue doesn't have that.
Is there a way to catch all keyup events in a Vue view? So I can catch that and set a variable to true for the message to be shown?
Now I have this added to all input models:
<input v-model="foo" @change="someThingChanged()">
Is there a way to catch all keyup events in a Vue view?
You can bind single onchange
event on the parent container and benefit from the fact that change events bubble:
<div class="container" @change="someThingChanged()">
<input v-model="foo">
<input v-model="bar">
... etc.
</div>
这篇关于组件中的 Vue 脏状态触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!