0๐
โ
Try with something like this:
store.js
state: {
plans: []
},
getters: {
loadedPlans(state) {
return state.plans
},
},
mutations: {
setPlans(state, plans) {
state.plans = plans
}
},
actions: {
async loadPlans({commit}) {
await this.$axios.get('http://localhost/api/plans', function(response) {
commit('setPlans', response.data)
})
}
}
plans.vue
async created() {
await this.$store.dispatch('loadPlans')
},
computed: {
myPlans() {
return this.$store.getters.loadedPlans
}
}
0๐
you can use a computed method for getting the value. The data object is evaluated once even perhaps before the state value is set. Modify your code as follows.
data:{
return {};
}
,computed: {
plans: this.$store.getters.loadPlans
}
Source:stackexchange.com