Answer the question
In order to leave comments, you need to log in
Is it necessary to check that the vuex state has already been loaded?
Greetings.
I have a repository where a list of cities is stored
export default new Vuex.Store({
state: {
cities: [],
},
mutations: {
SET_CITIES(state, payload) {
state.cities = payload;
}
},
getters: {
cities: (state) => {
return state.cities;
}
},
actions: {
fetchAllCities(context) {
axios.get('http://localhost:3000/cities', {
})
.then(response => {
context.commit('SET_CITIES', response.data)
});
}
},
modules: {}
});
{
path: "/cities",
name: "Cities",
component: () =>
import(/* webpackChunkName: "landing" */ "../views/cities/List.vue")
},
{
path: "/cities2",
name: "Cities2",
component: () =>
import(/* webpackChunkName: "landing" */ "../views/cities/List2.vue")
},
created: function() {
this.$store.dispatch('fetchAllCities');
},
actions: {
fetchOnceAllCities(context) {
if (this.state.cities.length) return; // <-----------
// loading only one time:
axios.get('http://localhost:3000/cities', {
})
.then(response => {
context.commit('SET_CITIES', response.data)
});
}
},
Answer the question
In order to leave comments, you need to log in
Why are you asking us? This is your application. In general, what you are talking about most likely does not require re-upload, so yes, most likely, in your case, verification is needed!
Usually reloading requires lists that can change frequently. In your case, I think that the data is not updated more than once a day / month / year
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question