AI助手支持GPT4.0
使用this.setData报‘of undefind’,怎么解?How to use this.setData to report ‘of undefind’?
使用this.setData报‘of undefind’,怎么解?
const app = getApp()Page({ data: { msg:"1234567890" }, onLoad() { wx.request({ url : 'http://127.0.0.1:7001/logined', data : { usname : "werewrr", password : "12345678" }, header: { 'content-type': 'application/json' }, method : "POST", dataType : 'json', success(res){ var d = res.data.data console.log(d) this.setData({ msg: 'd[0].username' }) } }) } })
const app = getApp()Page({ data: { msg:"1234567890" }, onLoad() { wx.request({ url : 'http://127.0.0.1:7001/logined', data : { usname : "werewrr", password : "12345678" }, header: { 'content-type': 'application/json' }, method : "POST", dataType : 'json', success(res){ var d = res.data.data console.log(d) this.setData({ msg: 'd[0].username' }) } }) } })
this的作用域不对
建议在wx.request 外面 声明 let self = this;
self.setData()