我的代码如下: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);
}
})
}
});
通过ajax,目前可以顺利读取接口数据,其中posts的数据有两项posts:Array(2) 0:Object
1:Object
我想通过that.setData将数据传给外层的data对象,以便其他页面调用
但是报错显示:Uncaught (in promise) TypeError: that.setData is not a function
还望指正,问题出在那里呢?谢谢!