正在回答
同学你好,老师这里也猜不到是为什么,需要使用代码测试。请将相关涉及到的代码全部复制粘贴上来(vue与js的)
如store中的js代码如下:
import Vuex from 'vuex'
export default Vuex.createStore({
state: {
cartList: {}
},
mutations: {
changeCartItemInfo(state, payload) {
const { shopId, productId, productInfo } = payload
let shopInfo = state.cartList[shopId] || {
shopName: '', productList:{}
}
let product = shopInfo.productList[productId]
if(!product) {
productInfo.count = 0
product = productInfo
}
product.count = product.count + payload.num
if(payload.num > 0) { product.check = true }
if(product.count < 0) { product.count = 0 }
shopInfo.productList[productId] = product
state.cartList[shopId] = shopInfo
},
changeShopName(state, payload) {
const { shopId, shopName } = payload
const shopInfo = state.cartList[shopId] || {
shopName: '', productList:{}
}
shopInfo.shopName = shopName
state.cartList[shopId] = shopInfo
},
changeCartItemChecked(state, payload) {
const { shopId, productId } = payload
const product = state.cartList[shopId].productList[productId]
product.check = !product.check
},
cleanCartProducts(state, payload) {
const { shopId } = payload
state.cartList[shopId].productList = {}
},
setCartItemsChecked(state, payload) {
const { shopId } = payload
const products = state.cartList[shopId].productList
if(products) {
for(let key in products) {
const product = products[key]
product.check = true
}
}
}
}
})
祝学习愉快!
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星