不知道哪里报错
来源:19-7 使用缓存实现文章收藏功能
qq_寄给你一朵玫瑰_0
2018-03-16
data:{ }, onLoad: function (option) { var postId = option.id; this.setData({ collected: postId }) var postsCollected = wx.getStorageSync('posts_ollected') // 判断是否生成缓存变量 if (postsCollected){ var postcollected = postsCollected[postId]; this.setData({ collecte: postcollected }) }else{ var postsCollected={}; postsCollected[postId]=false; wx.setStorageSync("posts_ollected", postcollected); } }, onCollectedTap: function (event) { var postsCollected = wx.getStorageSync('posts_collected'); var postCollected = postsCollected[collected]; // 收藏变成未收藏,未收藏变成收藏 postCollected = !postCollected postsCollected[collected] = postCollected; //文章是否收藏的缓存值 wx.setStorageSync(posts_ollected, postCollected) //跟新数据绑定变量,从而实现切换图片 this.setData({ collected: postCollected }) }
写回答
1回答
-
7七月
2018-03-16
群里下载下源码,最新的3月2日的,对postcollectd判空一下。
072018-04-02
相似问题