Skip to content Skip to sidebar Skip to footer

How To Set Dynamic Object Values With Vue/vuex?

I'm struggling to understand how to dynamically create & populate a key: value pairs in an object in my state using Vue/Vuex, here's an example: dataObject: {} (in state), and

Solution 1:

Vue set should do the work only your using it the wrong way:

Adds a property to a reactive object, ensuring the new property is also reactive, so triggers view updates. This must be used to add new properties to reactive objects, as Vue cannot detect normal property additions (e.g. this.myObject.newProperty = 'hi').

But the function arguments looks like this

  • {Object | Array} target
  • {string | number} propertyName/index
  • {any} value

https://vuejs.org/v2/api/#Vue-set

In your case it should be:

Vue.set(state.dataObject, 'total_operation_time',  payload[1]);
Vue.set(state.dataObject, 'machine_name',  payload[2]);

Post a Comment for "How To Set Dynamic Object Values With Vue/vuex?"