0👍
I do not think the problem is linked to fetch or asyncData.
You fetch the data and store it in the state. That’s good. But after that, you should not use the store.state
: use instead a getters (I find it cleaner to use mapGetters
).
Your store will be liked that :
export const state = () => ({
apibuilder: {},
});
export const getters = {
attributes(state) {
return state.apibuilder.currentModel.attributes;
}
}
And in your component :
import {mapGetters} from 'vuex';
export default {
computed: {
...mapGetters({
attributes: 'attributes',
}),
countAttributes() {
if (this.attributes) {
return Object.keys(this.attributes).length
}
}
}
}
Thanks to that, it will react to the change of data in the store.
- [Vuejs]-Jasmine spyOn applied to a method. A vue-test-utils async function is awaited. Now, the method is no longer a Jasmine spy. Why?
- [Vuejs]-Is this the correct way to use Vue.JS onChange function?
Source:stackexchange.com