Answer the question
In order to leave comments, you need to log in
Why doesn't watch work?
The setParams method does not work watch section
What could be the problem?
props: {
section:{ type: Object, default: false },
showModal:{ type: Boolean, default: false }
},
methods: {
setParams(param, itemId) {
let index = this.section.filter_values[param].indexOf(itemId)
if (index >= 0) {
this.section.filter_values[param].splice(index, 1);
} else {
this.section.filter_values[param].push(itemId)
}
},
}
watch: {
section (val, oldVal) {
console.log('change section filter');
}
}
Answer the question
In order to leave comments, you need to log in
The observer does not look into the depths. To do this, you need to Register which specific property you want to monitor:
watch('section.filter_values.param')
Or set an additional parameter deep: true
. Then it will recursively track all properties at any level of nesting.
Read more: https://vuejs.org/v2/api/#vm-watch
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question