当前位置: 代码迷 >> 综合 >> Cannot read property 'setData' of undefined;
  详细解决方案

Cannot read property 'setData' of undefined;

热度:94   发布时间:2023-11-04 22:12:43.0

原代码:

 wx.request({url: configurl.getcate,data: '',header: {'content-type': 'application/json' // 默认值},method: 'GET',dataType: 'json',responseType: 'text',success: function(res) {this.setData({cate: res.data})},fail: function(res) {},complete: function(res) {},})

运行结果:

修改:

 var that = this;wx.request({url: configurl.getcate,data: '',header: {'content-type': 'application/json' // 默认值},method: 'GET',dataType: 'json',responseType: 'text',success: function(res) {that.setData({cate: res.data})},fail: function(res) {},complete: function(res) {},})

 即可。

  相关解决方案