我在详细页面创建的方法
getCollect(){
// 将目前页面的内容放入storage中
const {
id,
currentIndex
} = this
wx.cloud.callFunction({
name: 'get_details_info',
data: {
id,
currentIndex
}
}).then(res => {
console.log(res);
this.collect = res.result.data
wx.setStorage({
key:'collect',
data: this.collect
})
//console.log(app.globalData.collect)
})
目前要在收藏页面读取collect对象却没法正常显示
<script>
const app = getApp()
export default {
name:"profileCollection",
data() {
return {
collect:{},
};
},
onShow() {
// 获取全局数组
const collect = wx.getStorageSync('collect')||[]
this.collect=collect
}
}
</script>
页面没法读出collect的内容(显示undefined)在组件中使用console.log也没法打印出对象
网友回复
dreamhunter:
// 获取全局数组
const collect = wx.getStorageSync('collect')||[]
//打印出来看看先
console.log(collect)
this.setData({
collect:collect
})
茜茜又困了🐽:
读缓存时用wx.getStorageSync(),存的时候就用wx.setStorageSync()。引用数据类型在存储时,最好先进行JSON序列化再存储
弱水三千,只取一瓢饮。:
https://developers.weixin.qq.com/miniprogram/dev/api/storage/wx.setStorageSync.html,用wx.setStorageSync这个试试