AI助手支持GPT4.0
wx.request的success中无发修改页面的初始数据?Didn’t modify the initial data of the page in the success of wx.request?
wx.request的success中无发修改页面的初始数据?
下面两个方法都无法修改初始化数据中的sms,第一种是没效果,第二种直接报sms_code为空。求各位前辈指点一下Page({ data: { TabCur: 0, scrollLeft:0, type: 0, btn_disabled:true, sms: 0 }, onLoad: function (options) { wx.request({ url: 'http://xxx/wx/login/config', success: function(res){ this.setData({ sms:res.data.data }) } }) },Page({ data: { TabCur: 0, scrollLeft:0, type: 0, btn_disabled:true, sms: 0 }, onLoad: function (options) { var sms_code; wx.request({ url: 'http://xxx/wx/login/config', success: function(res){ sms_code = res.data.data; } }) this.setData({ sms: sms_code }) },
The following two methods cannot modify SMS in initialization data. The first method is ineffective, and the second method reports SMS directly_ Code is empty. Please give me some advice / / page ({/ * * * initial data of page * / data: {tabcur: 0, s crollLeft:0 , type: 0, btn_ disabled:true , sms: 0 }, onLoad: function (options) { wx.request ({ url: ' http://xxx/wx/login/config ', success: function(res){ this.setData ({ sms:res.data.data }) } }) }, //Method 2 is not good either. Page ({/ * * * initial data of page * / data: {tabcur: 0, s) crollLeft:0 , type: 0, btn_ disabled:true , sms: 0 }, onLoad: function (options) { var sms_ code; wx.request ({ url: ' http://xxx/wx/login/config ', success: function(res){ sms_ code = res.data.data ; } }) this.setData ({ sms: sms_ code }) },
//作用域的问题,最外层加上var that = this:var that = thiswx.request({ url: 'http://xxx/wx/login/config', success: function(res){ that.setData({ sms:res.data.data }) }})