Vuex: Computed property not updating with state change

Created on 19 Mar 2017  ·  1Comment  ·  Source: vuejs/vuex

Sorry if I missed something; I searched all the closed issues and similar ones deal with updates to arrays; in my case it's a scalar. Also this is my first Vue/Vuex project so please educate me if I'm not doing things the right™ way.

I have a store with a state:

js const state = { currentAircraft: null, //[...] };

getters:

`js // [...] currentAircraft: state => state.aircraft

actions:

js // [...] setCurrentAircraft({commit}, {registration}) { return new Promise((resolve, reject) => { commit(types.SET_AIRCRAFT, {registration}); resolve(); }); },

and mutations:

js // [...] [types.SET_AIRCRAFT](state, {registration}) { state.currentAircraft = registration; state.allFlights = []; }, // [...]

and I have a component that uses the action and compares it to a property using a computed property:

js export default { props: ['aircraft'], computed: { ...mapGetters(['currentAircraft']), isActive() { console.debug(this.currentAircraft, this.aircraft); return this.currentAircraft === this.aircraft; } }, methods: { ...mapActions(['setCurrentAircraft', 'getAllFlights']), showAircraft() { this.setCurrentAircraft({registration: this.aircraft}).then(() => this.getAllFlights()); } } }

The problem is that after calling the showAircraft() action, the computed property is not re-computed. Any tips on how to find the issue?

Most helpful comment

Lol, it's important that your getter correctly poll the right state variable 🤦‍♂️

>All comments

Lol, it's important that your getter correctly poll the right state variable 🤦‍♂️

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gorbypark picture gorbypark  ·  3Comments

gdelazzari picture gdelazzari  ·  3Comments

Nickvda picture Nickvda  ·  3Comments

taoeffect picture taoeffect  ·  3Comments

jdittrich picture jdittrich  ·  3Comments