Vue.js watching deep properties

后端 未结 2 725
小蘑菇
小蘑菇 2020-12-21 09:35

I\'m trying to watch properties on a vue.js object, but i\'m not getting the result that i want, my code is the following:

var vueTable = new Vu         


        
相关标签:
2条回答
  • 2020-12-21 09:47

    You can use something with the looks of this

    this.$set(this.filters, 'name', "")

    Using $set (as described in https://vuejs.org/v2/guide/reactivity.html#Change-Detection-Caveats) the observable will be correctly added

    0 讨论(0)
  • 2020-12-21 09:55

    The documentation covers this here.

    Due to the limitations of modern JavaScript (and the abandonment of Object.observe), Vue cannot detect property addition or deletion.

    By starting with an empty object and setting v-model to filters.name, you end up adding a property dynamically. The best approach in this case would be to initialize the property in the data. It doesn't have to have a value.

    data: {
        filters: { name: null },
    }
    
    0 讨论(0)
提交回复
热议问题