微信小程序 this.setData is not a function
来源:互联网 发布:邮箱软件 编辑:程序博客网 时间:2024/05/16 18:17
微信小程序 this.setData is not a function
var that = this; wx.request({ url: 'http://52.214.109.210:5000/news?offset=0&limit=10', //仅为示例,并非真实的接口地址 data: { x: '', y: '' }, header: { 'content-type': 'application/json' }, success: function (res) { console.log(res.data.results); that.setData({ ajaxdata: res.data.results }) wx.showToast({ title: '成功', icon: 'success', duration: 2000 }) } })
小程序的一般函数中
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 })
正确请求方法:
var that = this; wx.request({ url: 'http://52.214.109.210:5000/news?offset=0&limit=10', //仅为示例,并非真实的接口地址 data: { x: '', y: '' }, header: { 'content-type': 'application/json' }, success: function (res) { console.log(res.data.results); that.setData({ ajaxdata: res.data.results }) wx.showToast({ title: '成功', icon: 'success', duration: 2000 }) } })
阅读全文
0 0
- 微信小程序 this.setData is not a function
- 微信小程序 报错:this.setData is not a function
- 微信小程序 this.setData is not a function
- 微信小程序 this.setData is not a function
- 微信小程序 this.setData is not a function;父元素获取
- 小程序之坑一TypeError: this.setData is not a function
- 论微信小程序的坑:thirdScriptError TypeError: this.setData is not a function
- 微信小程序 is not a function
- ExtJs this.addevents is not a function
- this.setState is not a function
- 微信小程序之this.setData
- extjs中出现this.addevents is not a function错误
- extjs中出现this.addevents is not a function错误
- Ext.this.addEvents is not a function错误
- Ext this.addEvents is not a function错误原因
- Extjs中this.swf.setDataProvider is not a function解决办法
- Ext this.addEvents is not a function 错误原因
- Extjs 报this.addEvents is not a function错误原因
- 存储设备读写速度测试
- JS复制文本到剪切板
- Customizing the Reference TV App
- test
- 设置文字不换行,超过的部分用“...”代替css实现
- 微信小程序 this.setData is not a function
- recyclerview点击事件与点击更改颜色
- 备份:关于mysqi的一些对比
- Python3.6 异常处理和assert
- MySQL存储过程及触发器
- ngx_lua模块api
- ctime函数使用遇到的坑
- HTML5文档结构
- c语言:sleep函数