1,首先初始化list 通过用户id初始化列表 userid
initList(state, playload) {
state.list = playload;//playload就应该是一个集合
},
说明下在初始话listf发现需要ischcked=false这个属性和属性值,通过map添加
async initList(context, playload) {//context是为了调用同步方法 playload是接收参数
//业务 根据登录的用户id去获取商品列表
let { data: list } = await myshoppingcarModel.query({
userid: playload
})
context.commit("initList", list.map(item => {
item.ischecked = false;
return item;
}));
},
2,通过商品id删除商品
deleteListById(state, playload) {//playload是id
state.list = state.list.filter(item => item.id != playload)
}
async deleteListById(context, playload) {
await myshoppingcarModel.del(playload);
context.commit("deleteListById", playload);
},