my code is as follows:
App({
data: {
posts: {}
},
onLaunch(event) {
// console.log("onLaunch");
var that = this;
swan.request({
url: "http://www.sfatpaper.com/content.json",
success: function (res) {
console.log(res.data);
that.setData({
posts: res.data.posts
});
},
fail: function (err) {
console.log(":" + err.errCode);
console.log(":" + err.errMsg);
}
})
}
});
at present, the interface data can be read smoothly through ajax, among which there are two items of posts data
posts:Array(2)
0:Object
1:Object
I want to pass the data to the outer data object through that.setData
so that other pages can call
but the error displays:
Uncaught (in promise) TypeError: that.setData is not a function
still hope to correct, what is the problem? Thank you!