购物车的数量的加减?
发布于 4 年前 作者 jingzou 1502 次浏览 来自 问答

点击加减数字变成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 回复

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

that.data.number
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
    })
   }
  })
回到顶部