在收藏和未收藏中会报错
来源:19-7 使用缓存实现文章收藏功能
慕圣9101672
2017-11-19
WAService.js:3 thirdScriptError
Cannot create property '0' on string '';at pages/logs/post-detail/post-detail page onColletionTap function
TypeError: Cannot create property '0' on string ''
写回答
2回答
-
gui_bin
2018-10-05
//显示收藏 未收藏
var postsCollected = wx.getStorageSync("posts_collected");
if (postsCollected === ""){//需要补上这个的判断
postsCollected = {};
}
if(postsCollected){
var postIsCollected = postsCollected[detailId];
if (postIsCollected){
this.setData({
collected: postIsCollected,
})
}else{
// var postsCollected = {};
postsCollected[detailId] = false;
wx.setStorageSync("posts_collected", postsCollected);
}
}
这么写试试,目测完美解决
00 -
7七月
2017-11-19
这个需要你调试下,你去读一个string的数组属性,这肯定是不对的。
00
相似问题