Answer the question
In order to leave comments, you need to log in
How in the child component to find out that the asynchronous data loading has ended?
There is a product route, which contains the id with the product in the url
{
path: '/product/:code',
props: true,
name: 'product',
component: () => import('../views/Product'),
meta: { scrollToTop: true },
},
created() {
this.$store.dispatch('GET_PRODUCTS');
}
async GET_PRODUCTS({ commit }) {
try {
const response = await axios.get('http://localhost:8080/db/db.json');
commit('setProducts', response.data);
} catch (error) {
console.log(error);
}
},
created() {
this.$store.dispatch('setProduct', this.code);
}
setProduct({ state, commit }, code) {
const products = state.products;
let product = null;
Object.values(products).some((val) => {
product = val.find((item) => item.code === +code);
return product;
});
const size = product.meta[0];
commit('setProduct', product);
commit('setSizeAndCost', size);
},
Answer the question
In order to leave comments, you need to log in
In App.vue I am querying all products from db
store.dispatch('GET_PRODUCTS').then(() => {
new Vue({ ... });
});
watch: {
'$store.state.products': {
immediate: true,
handler(products) {
if (products) {
// можно что-то сделать
}
},
},
},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question