Page({ /** * 页面的初始数据 */ data: { storageData: [] }, /** * 生命周期函数--监听页面加载 */
onLoad: function(options) { var that = this; console.log("getStorageSync " +
Array.isArray(wx.getStorageSync('testKey'))); if
(!Array.isArray(wx.getStorageSync('testKey'))) //判断本地缓存是否数组 { wx.setStorage({
key: 'testKey', data: that.data.storageData }) } }, // 删除本地缓存 delBtnClick:
function() { var that = this; wx.removeStorage({ key: 'testKey', success:
function(res) { that.setData({ storageData: [] }) }, }) }, // 添加本地缓存
addBtnClick: function() { var that = this; if
(!Array.isArray(wx.getStorageSync('testKey'))) //判断本地缓存是否数组 { wx.setStorage({
key: 'testKey', data: that.data.storageData }) } else { var logs =
wx.getStorageSync('testKey') logs.unshift(Date.now())
wx.setStorageSync('testKey', logs) } } }) <view><button
bindtap='addBtnClick'>新增</button></view> <view><button
bindtap='delBtnClick'>删除storage</button></view>