Skip to content
Advertisement

Using Vue.set in object with multiple nested objects

I am trying to use Vue.set() to update a state object in Vue 2.

This is what the object looks like:

JavaScript

So far, I was updating it with this mutation. I’m mutating each entry separately because they have different content.

JavaScript

Now, I’m trying to implement Vue.set() to avoid a change detection caveat.

My problem is that I can’t find the proper way to add it.

Here’s how Vue.set() is supposed to work :

JavaScript

So I tried this, which doesn’t seem to work because state.entries[index] is not an object of first rank :

JavaScript

But this doesn’t work either :

JavaScript

Any one has a clue what I’m doing wrong ?

Advertisement

Answer

The only non-reactive part is the new property you try to add in the fields object.

In order to add the googleInfos property, you have to set it in the mutation like this :

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement