html52.com
我爱小程序-开发者交流社区

在bindtouchend 事件中为data赋值,data的值为undefined?

代码如下:

changeTask: function(e) {
 
    var direction = e.detail.direction //滑动方向
    console.log(JSON.stringify(e))
    if (direction == 1) { //左滑
      if (this.currentSwiper > 0 && this.currentSwiper <= this.tasks.length - 1) {
        cSwiper -= 1
      }
    } else if (direction == 2) { //右滑
      if (this.currentSwiper >= 0 && this.currentSwiper < this.tasks.length - 1)
        cSwiper += 1
    } else { //没有滑动
      cSwiper = cSwiper
    }
    this.setData({
      currentSwiper: cSwiper
    })
    console.log("direction:" + direction + ";;this.currentSwiper:" + this.currentSwiper + ";;currentSwiper::" + cSwiper)
 
  }
 
})

其中cSwiper在 Page 上面定义的,即:

var cSwiper = 0

Page({

...

})

log输出为:

direction:2;;this.currentSwiper:undefined;;currentSwiper::0

即:data中的变量currentSwiper为undefined


评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

真正的个人免签约支付接口

云免签H5支付