[Vuejs]-How to automatically construct watch property based on data attributes in Vue.js?

0👍

Vue already watches properties of the data object (note if any of these values are themselves objects, I think you need to update the whole object, i.e. change its value to a shallow copy with the desired nested key-values).
Refer to: https://v2.vuejs.org/v2/guide/reactivity.html
You can then use the update lifecycle hook to watch for all changes to data: https://v2.vuejs.org/v2/api/#updated

-2👍

I was able to resolve a challenge using the following approach

created() {

    Object.keys(this.$data).forEach(key => {
      this.$watch(key, function() {
        // ... some logic to trigger on attribute change
      })
    })
}

Leave a comment