不好意思,老师,现在补发,关于收藏二次点击图标不会变更的问题
来源:19-7 使用缓存实现文章收藏功能
童莉莉
2018-01-29
/*detail.js部分代码*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
var postId = options.id;
console.log(postId);
this.setData({
currentPostId : postId
})
var postData = postsData.postList[postId];
this.setData({
postData:postData
})
var postsCollected = wx.getStorageSync('posts_collected')
if(postsCollected){
var postsCollected = postsCollected[postId]
this.setData({
collected:postsCollected
})
}
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: postsCollected
})
},
/*detail.wxml部分代码*/
<image wx:if="{{collected}}" catchtap="onCollectionTap" src="/images/icon/icon2.png"></image>
<image wx:else catchtap="onCollectionTap" src="/images/icon/icon1.png"></image>
谢谢老师啦
1回答
-
你看看图片,还是看不出清楚啊。这个问题,其实你还是需要断点调试一下,看下变量的状态,肯定是变量状态不对,才没有换过来。
032018-12-05
相似问题