Page(
{
data: {
pageNumber: 0,
categoryMenuList: '',
currentName: '',
tagId: 0
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var that = this;
wx.request({
url: '****************************',
method: 'post',
success: function (res) {
console.log('success:'+res.data);
that.setData({
categoryMenuList: res.data
});
}
})
console.log('typeof:'+typeof that.data);
console.log(that.data);
console.log('that.data.categoryMenuList:' + that.data.categoryMenuList);//这里无法打印出that.data.categoryMenuList很郁闷
}
})
遇到一个很无语的问题,取data中的categoryMenuList,始终得到的是初始值null
https://zhuanlan.zhihu.com/p/142764985 查看下 Chrome中devtool的延迟加载,主要是基于性能考虑
res.data[options.tapId],我想知道这有内容吗?
res.data[options.tapId]里的值就是 data对象中的currentCategoryName现在问题就出在 这个值上边,我在打印 this.data 对象的时currentCategoryName是有值的,当我打印this.data.currentCategoryName时就变成了NULL,你可以看我贴出来的最后一张图
完整代码发出来吧
Page(
{
data: {
pageNumber: 0,
categoryMenuList: '',
currentName: '',
tagId: 0
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var that = this;
wx.request({
url: '****************************',
method: 'post',
success: function (res) {
console.log('success:'+res.data);
that.setData({
categoryMenuList: res.data
});
}
})
console.log('typeof:'+typeof that.data);
console.log(that.data);
console.log('that.data.categoryMenuList:' + that.data.categoryMenuList);
}
})
没有出现你的问题,我的代码片段
https://developers.weixin.qq.com/s/ZN3KKZmQ7D6l