在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)
代码为更正后的代码
效果: