Page({
data: {}
onLoad: function (res) {
var that = this;
wx.request({
url: 'http://localhost:8080/wxcx.php',
data: {
name:count
},
header: {
'Content-Type': 'application/x-www-form-urlencoded'
},
method: "GET",
success: (res) => {
console.log(res.data)
that.setData({
re: res.data,
});
},
})
}
})
以上述代码为例怎么将服务器返回的re数据传递到data{}里面呢?
利用app.js中转
在这个js的顶部获取一下app:
const app = getApp();
Page({
..........
})
在拿到回调的地方进行赋值:
app.globalData.res = res.data;
其它所有想要再拿到这个数据的js里面同样只需要 const app = getApp();然后该js里面 app.globalData.res就拿到了