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 {
微信小程序 本地缓存wx.setStorage缓存设置和wx.removeStorage缓存删除
最新推荐文章于 2024-06-02 21:24:44 发布