在bindtouchend 事件中为data赋值,data的值为undefined?
发布于 5 年前 作者 mye 342 次浏览 来自 官方Issues

代码如下:

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

1 回复

你用了什么框架吗?

不然的话应该是 this.data.currentSwiper啊

回到顶部