postCollected is not defined ReferenceError: postCollected is not defined
来源:19-7 使用缓存实现文章收藏功能
慕仰0394571
2020-06-19
var postsData=require(’…/…/…/data/post-data.js’)
Page({
date:{
},
onLoad:function(option){
var postId=option.id;
this.data.currentPostId=postId;
var postData=postsData.postList[postId];
//this.data.currentPostId=postId;
this.setData({
postData:postData,
currentPostId:postId
});
var postsCollected=wx.getStorageSync(‘posts_collected’);
if(postsCollected){
var postColllected=postsCollected[postId];
if(postCollected){
this.setData({
collected:postCollected
})
}
}
else{
var postsCollected = {};
postsCollected[postId]=false;
wx.setStorageSync(‘posts_collected’, postsCollected);
}
},
onCollectionTap:function(event){
var postsCollected=wx.getStorageSync(‘posts_collected’);
var postCollected=postsCollected[this.data.currentPostId];
postCollected=!postCollected;
postsCollected[this.data.currentPostId]=postCollected;
wx.setStorageSync(‘posts_collected’, postsCollected);
this.setData({
collected: postCollected
})
}
})
这段代码第一遍点进去是正确的,第二次进去后就出现错误,也按老师的做法添加了 if(postCollected){},但错误依然。
postCollected is not defined ReferenceError: postCollected is not defined
2回答
-
建议自己调试下,提示好明确啊,没有定义
如果要老师帮看,麻烦把代码格式贴好,这看不了
00 -
三姐四哥五弟
2020-07-30
请问有没有解决,怎么解决的,能告知一下不,我也遇到了这个问题。
012020-07-30
相似问题