Web前端最全vuex实现购物车的增加减少移除,web前端面试题及答案2024

最后

开源分享:【大厂前端面试题解析+核心总结学习笔记+真实项目实战+最新讲解视频】

给大家分享一些关于HTML的面试题。


}, 100)

},

// 减

reducedCar({ commit }, params) {

// console.log(params) //点击添加传过来的参数

// 使用setTimeout模拟异步获取购物车的数据

setTimeout(function () {

let result = ‘ok’

if (result == ‘ok’) {

// 提交给mutations

commit(“reducedCar”, params)

}

}, 100)

},

// 移出

deleteCar({ commit }, params) {

// console.log(params) //点击添加传过来的参数

// 使用setTimeout模拟异步获取购物车的数据

setTimeout(function () {

let result = ‘ok’

if (result == ‘ok’) {

// 提交给mutations

commit(“deleteCar”, params)

}

}, 100)

}

// initCar({ commit }) {

// setTimeout(function () {

// let result = ‘ok’

// if (result == ‘ok’) {

// // 提交给mutations

// commit(“initCar”, [{

// “id”: 20193698,

// “title”: ‘我是购物车原来的’,

// “price”: 30,

// “num”: 100,

// }])

// }

// }, 100)

// }

},

getters: {

//返回购物车的总价

totalPrice(state) {

let Carlen = state.carList;

let money = 0;

if (Carlen.length != 0) {

Carlen.forEach((item) => {

money += item.price * item.num

})

return money;

} else {

return 0;

}

},

//返回购物车的总数

carCount(state) {

return state.carList.length

}

},

})

2. list.vue(商品列表)

跳转到购物车

<el-button @click=“addCar(scope.row)” type=“text” size=“small”>加入购物车

  1. car.vue(购物车)

合计:总共{{count}}个商品,总价{{totalPrice}}元

空空如也!·······

<el-button @click=“reduceFun(scope.row)” type=“text” size=“small”>-

{{scope.row.num}}

<el-button @click=“addCar(scope.row)” type=“text” size=“small”>+

<el-button @click=“deleteFun(scope.row)” type=“text” size=“small”>删除

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值