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()
在wx.request外 声明let _this = this _this.setData({})
success: (res) => { var d = res.data.data console.log(d) this.setData({ msg: d[0].username }) }