Answer the question
In order to leave comments, you need to log in
Please explain about curly braces in Vuex?
I often notice curly braces in projects, what are they for? why without them?
And when are they used and when are they not?
const actions = {
addToCart({ commit }, product){
commit('addProduct', {
id: product.id,
price: product.price
})
},
removeToCart({commit}, product){
commit('removeProduct', {
id: product.id,
price: product.price
})
}
}
const mutations = {
addProduct(state, {id, price}) {
const record = state.cart.find(p => p.id === id)
if (!record) {
state.cart.push({
id,
price,
quantity: 1
})
} else {
record.quantity++
}
},
Answer the question
In order to leave comments, you need to log in
https://developer.mozilla.org/en/docs/Web/JavaScri...
https://developer.mozilla.org/en/docs/Web/JavaScri...
This is packaging into objects. For example, to transfer several variables in one.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question