Quantcast
Viewing all articles
Browse latest Browse all 3

Answer by dynamiclynk for How to update Vue component property when Vuex store state changes?

I had this issue when trying to add new properties to my user state so I ended up with this and it works well.

Action in Vuex store

   updateUser (state, newObj) {      if (!state.user) {        state.user = {}      }      for (var propertyName in newObj) {        if (newObj.hasOwnProperty(propertyName)) {          //updates store state          Vue.set(state.user, propertyName, newObj[propertyName])        }      }    }

Implementation

Call your store action above from the Vue component

this.updateUser({emailVerified: true})

Object

{"user":{"emailVerified":true},"version":"1.0.0"}

Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>