课程8-10设置postsCllected读取缓存,新增的_ postsCllected使用小程序提供的清楚数据缓存后报错
来源:8-12 同步文章缓存状态
降维
2021-02-15
如果缓存中有对象存在,点击就不会报错
不知道你们有没有遇到这样
4回答
-
田野落日
2021-04-29
const postsCollected = {...this.data._postsCollected}
这样就可以了。
222023-08-16 -
降维
提问者
2021-02-15
到了零晨5点,查了资料才知道怎么改
onCollect(event){
var postsCollected = this.data._postsCollected
//判断postsCollected的空对象去做的事情
if(postsCollected == ''){
const postsCollected = {}
postsCollected[this.data._pid] = !this.data.collected
this.setData({
collected:!this.data.collected
})
wx.setStorageSync('posts_collected', postsCollected)
}else{
const postsCollected = this.data._postsCollected
postsCollected[this.data._pid] = !this.data.collected
this.setData({
collected:!this.data.collected
})
wx.setStorageSync('posts_collected', postsCollected)
}
},
20 -
夯实理想
2021-03-14
if(!postsCollected){
postsCollected={}
}
00 -
若鱼
2021-03-02
const postCollected = wx.getStorageSync('post-collected')
if (postCollected == '') {
this.data._postCollected = {}
} else {
this.data._postCollected = postCollected
}
00
相似问题