BUG反馈,关于使用setStorageSync中遇到的BUG
发布于 5 年前 作者 xlei 12882 次浏览 来自 问答

代码片段如下:

wx.setStorageSync(this.data.key, this.data.list)

var gGoodList = wx.getStorageSync(“goodList”)

var gBadList = wx.getStorageSync(“badList”)

console.log("------start------")

console.log(gGoodList)

console.log(gBadList)

gGoodList = gGoodList ? gGoodList :[]

gBadList = gBadList ? gBadList : []

gGoodList[this.data.key] = this.data.goodList

gBadList[this.data.key] = this.data.badList

wx.setStorageSync(“goodList”, gGoodList)  //gGoodList有数值,使用setStorageSync覆盖缓存goodList的值

console.log(gGoodList)

wx.setStorageSync(“badList”, gBadList)

console.log(gBadList)

console.log("------end------")

console.log(wx.getStorageSync(“goodList”))  //为何覆盖之后缓存goodList还是为空白数组[]

console.log(wx.getStorageSync(“badList”))

console.log("------new------")

工具中测试console输出如下:

------start------

[]

[]

[测试: Array(0)]

[测试: Array(1)]

------end------

[]

[]

------new------

微信中测试输入如下:

[]

[]

[]

[]

------end------

[]

[]

------new------

2 回复

谢谢回答,后面测试发现array中有array的无法储存,换别的方式解决了

这个接口貌似确实有问题,我们一个小程序,有些手机没有问题,有些set后再get就是空,晕,被坑了好久啊,尤其是苹果手机,尽量还是缓存在内存吧,要永久存储就丢到服务端,不要依赖这个接口

回到顶部