微信小程序做一個加入購物車功能

一 加入緩存的大體思路

在這裏插入圖片描述

標題

在這裏插入圖片描述
在這裏插入圖片描述

疑惑點

一 Q: 這個箭頭函數是什麼
在這裏插入圖片描述
A :
在這裏插入圖片描述
在這裏插入圖片描述

handlePreviewImage(e){
    const urls=this.GoodsInfo.pics.map(v=>v.pics_mid);
    const current=e.currentTarget.dataset.url;
    wx.previewImage({
      current,
      urls
    });
  },
  handleCartAdd(){
    let cart=wx.getStorageSync("cart")||[];
    let index=cart.findIndex(v=>v.goods_id===this.GoodsInfo);
    if(index===-1){
      this.GoodsInfo.num=1;
      cart.push(this.GoodsInfo);
    }else{
      cart[index].num++;
    }
  
  wx.setStorageSync("cart",cart);
  wx.showToast({
    title: '不是要剁手嗎',
    icon:"success",
    mask:true
  });

  }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章