微信小程序 wx:setStorage和wx:getStorage 数据存取

1、wx:setStorage() (uniapp写法,uni.setStorage)

将数据存储在本地缓存中指定的key中,它会覆盖掉原来该key 对应的内容。

数据存储生命周期跟小程序本身一致,即除用户主动删除或超过一定时间被自动清理。 否则数据一直可用。 单个 key允许存储的最大数据长度为1MB,  所有数据存储上限为 10MB。

示例:

myset01(){
wx.setStorage({
data: "小程序项目开发",
key: '01',
success(res){
console.log("==setStorage成功 res=="+JSON.stringify(res));
}
})
},

 

2、wx.getStroage()   (uniapp写法,uni.getStroage)

从本地缓存中异步获取指定key 的内容。

示例:

myget01(){
var that = this;
wx.getStorage({
key: '01',
success(res){
that.setData({
storage_data: res.data,
})
}
})
},

 

3、wx.removeStorage()   (uniapp写法,uni.removeStorage)

从本地缓存中移除指定的key

示例:

myremove01(){
wx.removeStorage({
key:'01',
success(res){
console.log("remove key 成功");
},fail(res){
}
})
},

 

4、wx.clearStorage()   (uniapp写法,uni.clearStorage)

清空所有缓存数据。

示例:

myclear01(){
wx.clearStorage({
success(res){
console.log("clearStorage 成功");
},
})
},

 

posted @   蓦然JL  阅读(1747)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
  1. 1 唯一 G.E.M.邓紫棋
  2. 2 他只是经过 白敬亭 魏大勋
  3. 3 Uptown Funk Mark Ronson / Bruno Mars
  4. 4 在你的身边 盛哲
  5. 5 Edge of My Life Manafest
  6. 6 凄美地 郭顶
  7. 7 Wonderful Tonight Boyce Avenue
  8. 8 心如止水 Ice Paper
  9. 9 Sugar Maroon 5
  10. 10 静谧时光 JIAxNING
  11. 11 Right Now (Na Na Na) Aamir
  12. 12 Dangerously Charlie Puth
  13. 13 Someone You Loved Madilyn Paige
  14. 14 Shape of My Heart Boyce Avenue
  15. 15 We Can't Stop Boyce Avenue / Bea Miller
  16. 16 Perfect Boyce Avenue
  17. 17 Love Me Like You Do Boyce Avenue
  18. 18 Thank You Boyce Avenue
  19. 19 Don’t Wanna Know Boyce Avenue / Sarah Hyland
他只是经过 - 白敬亭 魏大勋
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

Not available

访问主页
关注我
关注微博
私信我
返回顶部
点击右上角即可分享
微信分享提示

目录导航