购物车的数量的加减?

发布于 6 年前作者 jingzou1733 次浏览最后编辑 6 年前来自 ask

点击加减数字变成NaN了怎么?

jian(){
    let that = this
    that.number = that.number - 1 * 1
    console.log(that.number)

  },
  jia(){
    let that = this
    console.log(that.number)

    that.setData({
      number : that.number + 1 * 1
    })
  },

3 回复
omeng
omeng1 楼5 年前

你that.number哪里来的。data里来的不应该是that.data.number?

yong85
yong852 楼5 年前
that.data.number
xiaoxiuying
xiaoxiuying3 楼4 年前
Page({
  /**
   * 页面的初始数据
   */
  data: {
    itemNum:1
  },
  addition(){
    const newItemNum = this.data.itemNum+=1;
    this.setData({
      itemNum:newItemNum
    })
  },
  subtract(){
    const {itemNum} = this.data;
    if(itemNum===1){
        return
    }
    this.setData({
      itemNum:itemNum+=1
    })
   }
  })