Answer the question
In order to leave comments, you need to log in
Vuex for a directory with a basket - what is the best way to implement such a solution?
I took an example of a directory from the official documentation as a basis ( link
We have a repository with such a structure (conditionally)
products: [{}, {}, {}, ...] // массив объектов с данными товаров
cartItems: [{id:1, quantity: 1}, ...] // объесты со ссылками на id товара в products и количеством
getters:
cartProducts: (state, getters, rootState) => {
return state.items.map(({ id, quantity }) => {
const product = rootState.products.all.find(product => product.id === id)
return {
title: product.title,
price: product.price,
quantity
}
})
}
}
Answer the question
In order to leave comments, you need to log in
get data for the cart - in actions, through Promise.all by id, pulling out data for each product?
If there are no products you need in products, upload them.
You have an action that loads products on the page.
Make an action that will load products by id array.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question