微信小程序 this.setData is not a function
在一般的函数中:
bindFaChange1: function (e) {
console.log('picker发送选择改变,携带值为', e.detail.value)
this.setData({
index1: e.detail.value
})
}
this.setData是正确的。
但当在函数中有个请求(wx.request)时:
formSubmit: function (e) {
wx.request({
method: 'POST',
header: header,
url: url,
dataType: 'json',
success: function (res) {
this.setData({
data1: true
})
}
})
}
这样会报错误:this.setData is not a function.
解决方法就是 :在请求(wx.request)外面添加:var that=this;将success中的
this.setData({
data1: true
})
改为:
that.setData({
data1: true
})
posted on
2017-12-09 23:41
飞狐爷 阅读(
...) 评论(
...)
编辑
收藏
转载于:https://www.cnblogs.com/cyxxzjp/p/8013174.html
最后
以上就是害怕蚂蚁最近收集整理的关于微信小程序 this.setData is not a function的全部内容,更多相关微信小程序内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。

发表评论 取消回复