AAAAAAAAAAAAAAAAA

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA :) :) :) :) :) :)
<script> export default { data() { return { navBarHeight: '', isCollect: false, isshow: false, showCar: false, shopDate: {}, shopId: 0, qg: false }; }, computed: { // 从 Vuex 映射数据 cartItems() { return this.$store.state.cartItems }, totalAmount() { return this.$store.state.totalAmount }, totalPrice() { return this.$store.state.totalPrice }, itemWithIdOne() { const foods = this.cartItems; // 安全判断 if (!Array.isArray(foods)) { this.qg = false; return { id: this.shopId, title: '商品名称商品名称', buySum: 0 }; } // 查找当前商品 const found = foods.find(food => food.id === this.shopId); if (found) { this.isshow = true; this.qg = true; // 表示已在购物车,显示加减按钮 return found; } else { // 未找到,设置 qg = false(可以抢购) this.qg = false; this.isshow = false; return { id: this.shopId, title: '商品名称商品名称', buySum: 0 }; } } }, methods: { car() { this.showCar = true; }, add(item) { const product = { id: this.shopId, title: this.itemWithIdOne.title, // 注意加 this. price: this.itemWithIdOne.price || 38 }; this.$store.dispatch('addToCart', product); }, // 减少商品数量(点击 -) decrease(item) { this.$store.dispatch('decreaseFromCart', item.id); // item.id 存在 }, // 抢购按钮(首次加入) addCar() { this.qg = true this.isshow = true const product = { id: this.shopId, title: '商品名称商品名称', price: 38, buySum: 0 }; this.$store.dispatch('addToCart', product); console.log("AAAAAAAAAAAAAAAAA", this.$store.dispatch('addToCart', product)) }, goOrder() { uni.navigateTo({ url: '/pages/order/order' }) }, goback() { uni.navigateBack({ delta: 1 }) }, Collect() { this.isCollect = !this.isCollect }, // addCar() { // console.log("isshow", this.isshow) // }, onLoad(options) { const id = Number(options.id); // 强制转数字 if (isNaN(id)) { console.error('无效的 id'); return; } this.shopId = id; this.$nextTick(() => { const statusBarHeight = uni.getSystemInfoSync().statusBarHeight const menuButtonInfo = uni.getMenuButtonBoundingClientRect() this.navBarHeight = statusBarHeight }) } } } </script> <view class="padding-sm flex justify-between align-center" style="position: relative;"> <!-- 商品名称商品名称{itemWithIdOne.title} --> <view class="text-bold" style="font-size: 30rpx;"> {{itemWithIdOne.title}} </view> <view class=""> <view v-if="qg" class="flex align-center justify-center"> <view class="flex justify-center align-center" style="width: 36rpx; height: 36rpx; border-radius: 50%; background-color: #f0f0f0;" @click.stop="decrease(itemWithIdOne)"> <u-icon name="minus-circle" size="36rpx" color="#AAA8A7"></u-icon> </view> <text class="margin-lr-xs" style="font-size: 28rpx; border-radius: 8rpx; background-color: #D9D9D9; color: #333; min-width: 40rpx; text-align: center;"> {{ itemWithIdOne.buySum}} </text> <view @click.stop="add(itemWithIdOne)" class="flex justify-center align-center" style="width: 36rpx; height: 36rpx; border-radius: 50%; background-color: #fff;"> <u-icon name="plus-circle" color="#FC7746" size="36rpx"></u-icon> </view> </view> <view v-else class="flex justify-center text-bold align-center buy" @click="addCar()"> <view class=""> <u-image src="https://env-00jxta4kb22c.normal.cloudstatic.cn/1/static/my/collect/buy.png" height="22" width="22"></u-image> </view> <view class=""> 抢购 </view> </view> </view> </view> 为什么首次点击添加会直接添加两个数量
10-29
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值