},
onLoad:function(option){
//接收posts.js 传递过来的postId
//posts.js中 url: “post-detail/post-detail?id=” + postId
var postId = option.id;
this.data.currentPostId = postId;
var postData = postsData.postList[postId];
//数据绑定
// this.data.postData = postData;
this.setData({
postData: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){
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
})
}
})
4年同步微信官方迭代,累计20000+人学习, 比微信官方更火爆!
了解课程