Skip to content Skip to sidebar Skip to footer

Update Data Property / Object In Vue.js

is there a way I can programmatically update the data object / property in vue.js? For example, when my component loads, my data object is: data: function () { return {

Solution 1:

Vue does not allow dynamically adding new root-level reactive properties to an already created instance. However, it’s possible to add reactive properties to a nested object, So you may create an object and add a new property like that:

data: function () {
    return {
        someObject:{
            cars: true,
    }
}

and add the property with the set method:

methods: {
        click_me: function () {
            this.$set(this.someObject, 'planes', true)
        }
    }

for vue 1.x use Vue.set(this.someObject, 'planes', true)

reactivity

Post a Comment for "Update Data Property / Object In Vue.js"