商品详情 点击 图标切收藏
<view class="goods_collect"><!--isCollect值为true加载icon-shoucang图标,false加载icon-shoucang1图标--><text class="iconfont {{isCollect?'icon-shoucang':'icon-shoucang1'}}"></text><view class="collect_text">收藏</view></view>
修改样式(选中icon-shoucang图标)
pagesgoos_detailindex.less
.goods_collect{.icon-shoucang{color: var(--themeColor); /*主题颜色*/}}
给收藏图标绑定点击事件
<view class="goods_collect" bindtap="handleCollect">...
pagesgoos_detailindex.js
// 点击 商品收藏图标handleCollect(){let isCollect=false;// 1 获取缓存中的商品收藏数组let collectStorageSync("collect")||[];// 2 判断该商品是否被收藏过let index=collect.findIndex(v=&ds_id===ds_id);// 3 当index!=-1表示已经收藏过if(index!==-1){// 能找到已经收藏过了在数组中删除该商品collect.splice(index,1);isCollect=false;wx.showToast({title: '取消成功',icon: 'success',// true防止用户 手抖 疯狂点击按钮mask: true,});}else{// 没有收藏过collect.push(this.GoodsInfo);isCollect=true;wx.showToast({title: '收藏成功',icon: 'success',mask: true,});}// 4 把数组存入到缓存中wx.setStorageSync( "collect", collect);// 5 修改data中的属性iscollectthis.setData({isCollect})}
选中一个商品 点击收藏——>再换第二个商品 点击收藏
本文发布于:2024-01-27 23:17:39,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/17063686583248.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |