敢为人鲜小程序前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

23 lines
673 B

// store/modules/cartNum.js
// 这是管理分类列表加入购物车数量的store
import Vue from 'vue'
export default {
namespaced: true,
state: {
productCounts: {} // 格式:{ 商品ID: 数量 }
},
mutations: {
// 增加商品数量
incrementProduct(state, { productId, amount = 1 }) {
const currentCount = state.productCounts[productId] || 0
Vue.set(state.productCounts, productId, currentCount + amount)
}
},
getters: {
// 获取指定商品数量
getProductCount: (state) => (productId) => {
return state.productCounts[productId] || 0
}
}
}