跟老师代码一样的,为什么点击收藏没有效果呢?
来源:19-11 同步异步方法对比
Follow_the_self
2018-08-28
var postsData = require('../../../data/posts-data.js') Page({ data: { }, onLoad: function(option) { var postId = option.id; this.data.currentPostId = postId; var postData = postsData.postList[postId]; this.setData({ post_Data: postData, }) var postsCollected = wx.getStorageSync('posts_Collected') if (postsCollected) { var postCollected = postsCollected[postId] if (postCollected) { this.setData({ collected: postCollected }) } } else { var postsCollected = {} postsCollected[postId] = false; wx.setStorageSync('posts_Collected', postsCollected) } }, onCollectionTap: function(event) { // this.getPostsCollectedSyc(); this.getPostsCollectedAsy(); }, getPostsCollectedAsy: function() { var that = this; wx.getStorage({ key: "posts_collected", success: function(res) { var postsCollected = res.data; var postCollected = postsCollected[that.data.currentPostId]; //收藏变成未收藏,未收藏变成收藏 postCollected = !postCollected; postsCollected[that.data.currentPostId] = postCollected; that.showToast(postsCollected, postCollected); } }) }
写回答
1回答
-
慕虎9030788
2018-08-28
报什么错?
wxml是不是没写catchtap
012018-08-30
相似问题