Answer the question
In order to leave comments, you need to log in
How to track any changes in the data object?
I'm scratching my head over the problem. There is an Article.vue component in steal. I want to use the same component for both creating and updating. And in the second case, I need to track ANY changes to existing data (which come from the back). I'm trying to do with watch, but it doesn't work.
props: ['articleProp'],
data() {
return {
article: {
title: null,
description: null
}
}
},
watch: {
article: {
deep: true,
handler(newValue, oldValue) {
console.log('triggered')
}
}
},
mounted() {
if (this.articleProp) {
Object.keys(this.articleProp).filter(key => key in this.article).forEach(key => {
this.article[key] = this.articleProp[key]
})
}
}
this.article
to mounted and watch is triggered when I don't need it. In addition, the watcher returns both identical values and it is impossible to track anything!!! I don't understand at all what to do? Answer the question
In order to leave comments, you need to log in
watch works when I don't need to
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question