/*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>
谢谢老师啦
4年同步微信官方迭代,累计20000+人学习, 比微信官方更火爆!
了解课程