微信小程序开发学习 第十四天 success()函数data未定义以及点击按钮弹出选择框

在success(res)函数中data未定义:

代码:

 addAction1: function () {
    wx.showActionSheet({
      itemList: ['胸部伸展', '跪姿俯卧撑', '蹲起跳','早安式伸展','俯卧挺身Y,T,W型','腹部拉伸',],
      success (res) {
        console.log(res.tapIndex)
        console.log(this.data.showActionList)
      },
      fail (res) {
        console.log(res.errMsg)
      }
    })
  }

报错:

在这里插入图片描述

更正:

在wx.showActionSheet()外加上一句var that = this

addAction1: function () {
    var that = this
    wx.showActionSheet({
      itemList: ['胸部伸展', '跪姿俯卧撑', '蹲起跳','早安式伸展','俯卧挺身Y,T,W型','腹部拉伸',],
      success (res) {
        console.log(res.tapIndex)
        console.log(that.data.showActionList)
      },
      fail (res) {
        console.log(res.errMsg)
      }
    })
  }

效果:

在这里插入图片描述

点击按钮弹出选择框

参考:微信开发文档 wx.showActionSheet(Object object)
代码为更正后的代码
效果:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值