代码片段如下:
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------