How to implement dirty state in VueJs
You can use the deep
option of watch
as shown in the manual
var app = new Vue({
el: '#app',
data:
{
model:
{
a:0,
b:'',
c:
{
c1:null,
c2:0,
c3:'test'
}
},
dirty: false
},
watch:
{
model:
{
handler(newVal, oldVal)
{
this.dirty = true;
},
deep: true
}
}
});
Borrowing from -- > https://stackoverflow.com/a/48579303/4050261
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>