Cannot read property 'setData' of undefined;

原代码:

 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) {},
      })

运行结果:

Cannot read property 'setData' of undefined;_第1张图片

修改:

 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) {},
 })

 即可。

你可能感兴趣的:(微信小程序)