Vue: How to update multi $data property?

Created on 21 Nov 2015  ·  7Comments  ·  Source: vuejs/vue

First of all thanks for Vue, it's greate solution for me

this is my Vue Instance
new Vue({
data:{
a:1,
b:2,
c:3
}
....
});

I want update a,b,c by once, how did it?

Most helpful comment

All 7 comments

Just set them one by one?...
Please don't use issues to ask questions.

You can just update them one by one. Vue batches DOM updates and watchers
calls for you.

@yyx990803 can you please provide a way to update(actually it's replace) the object that referenced by $data, e.g. vm.loadData(a new object with same struct) etc.

@Akryum Thank you very much, I'll try it.

@Akryum THanks 👍

for those who don't have the time to click :

...
,
  methods: {
    replaceData () {
      const newData = {
        a: 1,
        b: 2,
        c: 3,
      }
      Object.assign(this.$data, newData)
    }
  },
...
Was this page helpful?
0 / 5 - 0 ratings