我的代碼如下: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('錯(cuò)誤碼:' + err.errCode);
console.log('錯(cuò)誤信息:' + err.errMsg);
}
})
}
});通過(guò)ajax,目前可以順利讀取接口數(shù)據(jù),其中posts的數(shù)據(jù)有兩項(xiàng)posts:Array(2) 0:Object
1:Object我想通過(guò)that.setData將數(shù)據(jù)傳給外層的data對(duì)象,以便其他頁(yè)面調(diào)用但是報(bào)錯(cuò)顯示:Uncaught (in promise) TypeError: that.setData is not a function還望指正,問(wèn)題出在那里呢?謝謝!
請(qǐng)問(wèn)在小程序中如何從請(qǐng)求success中將數(shù)據(jù)返回給對(duì)象data?
尚方寶劍之說(shuō)
2018-12-17 09:28:12