代码片段如下:
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------
微信小程序开发相关问题解答;本文来自微信小程序工厂 http://www.xcxgc.com 转载请保留。
微信小程序开发者回答:
杜***:
这个接口貌似确实有问题,我们一个微信小程序,有些手机没有问题,有些set后再get就是空,晕,被坑了好久啊,尤其是苹果手机,尽量还是缓存在内存吧,要永久存储就丢到服务端,不要依赖这个接口
蜗***:
谢谢回答,后面测试发现array中有array的无法储存,换别的方式解决了
【微信小程序问答】textarea和view组件在ios和android上padding表现不一致 ...
本文网址:http://www.91bianli.com/kaifazhinan/72675.html