异步存储:wx.setStorage
同步存储:wx.setStorageSync
异步获取:wx.getStorage
同步获取:wx.getStorageSync
wx.setStorage({
key:"key",
data:"value"
})
//或
wx.setStorage({
key:"key",
data:"value",
encrypt: true, // 若开启加密存储,setStorage 和 getStorage 需要同时声明 encrypt 的值为 true
success() {
//设置本地存储后的回调
}
})
wx.setStorage 与 wx.setStorageSync的区别是:
wx.setStorage为异步存储--无论方法执行成功与否,都会继续向下执
wx.setStorageSync为同步存储--必须要同步方法处理完,程序才能继续向下执行
使用异步,性能会更好;而使用同步,数据会更安全。