其实这个存储在新建Demo的时候就已经用到了就是存储就是那个logs日志,数据存储主要分为同步和异步
异步存储方法:
存数据
wx.setStorage(object) 相同key会覆盖,可写回调方法
获取方法:
wx.getStorage(object)
清除方法:
wx.clearStorage()里面可以写回调函数 成功,失败,完成
同步存储方法:
存数据 相同key会覆盖
wx.setStorageSync(key,data)
读数据
wx.getStorageSync(key) 存储是指定的key
清除数据
wx.clearStorageSync() 不可写回调方法
wxml
<!--动态获取数据--> <text>{{storageContent}}</text> <!--存--> <button type="primary" bindtap="listenerStorageSave">storage存储信息会在text上显示</button> <!--取--> <button type="primary" bindtap="listenerStorageGet">获取storage存储的信息</button> <!--清--> <button type="warn" bindtap="listenerStorageClear">清楚异步存储数据</button> <text>{{storageSyncContent}}</text> <button type="primary" bindtap="listenerStorageSyncSave">storageSync存储信息会在text上显示</button> <button type="primary" bindtap="listenerStorageSyncGet">获取storageSync存储信息</button> <button type="warn" bindtap="listenerStorageSyncClear">清除同步存储数据</button>
js
Page({ data:{ // text:"这是一个页面" storageContent: '', storageSyncContent: '' }, onLoad:function(options){ // 页面初始化 options为页面跳转所带来的参数 }, /** * 异步存储 */ listenerStorageSave: function() { //以键值对的形式存储 传进去的是个对象 wx.setStorage({ key: 'key', data: '我是storeage异步存储的信息', success: function(res) { console.log(res) } }) }, /** * 异步取信息 */ listenerStorageGet: function() { var that = this; wx.getStorage({ //获取数据的key key: 'key', success: function(res) { console.log(res) that.setData({ // storageContent: res.data }) }, /** * 失败会调用 */ fail: function(res) { console.log(res) } }) }, /** * 清除数据 */ listenerStorageClear: function() { var that = this; wx.clearStorage({ success: function(res) { that.setData({ storageContent: '' }) } }) }, /** * 数据同步存储 */ listenerStorageSyncSave: function() { wx.setStorageSync('key', '我是同步存储的数据') }, /** * 数据同步获取 */ listenerStorageSyncGet: function() { // var that = this; var value = wx.getStorageSync('key') this.setData({ storageSyncContent: value }) }, /** * 清除同步存储数据 */ listenerStorageSyncClear: function() { wx.clearStorageSync() }, onReady:function(){ // 页面渲染完成 }, onShow:function(){ // 页面显示 }, onHide:function(){ // 页面隐藏 }, onUnload:function(){ // 页面关闭 } })
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月20日
2024年09月20日
- [雨果唱片]李冰《地方民歌·戏曲系列-爱的颂歌》WAV
- 《模拟人生》真人电影官宣!玛格特·罗比担任制片人
- 《星战绝地》系列玩家数超4000万!续作表现超预期
- EA称AI是其业务核心!能提高开发效率、节约成本
- 《十年经典成名好歌 高品质最佳音乐 2CD》[WAV/分轨][1GB]
- 《8个男人的故事 2CD》[WAV/分轨][1GB]
- 《粤语超白金 百听不厌的经典金曲 2CD》[WAV/分轨][1.3GB]
- 群星.1994-全世界精丫华星】【WAV+CUE】
- 杜德伟.1997-知.解2CD【滚石】【WAV+CUE】
- 群星.2022-一不小心喵上你原声大碟【TME影音】【FLAC分轨】
- 《战锤40K星际战士2》卡在正在加入服务器解决方法
- 《勇者斗恶龙怪物仙境3》玩法内容介绍
- 《幸福工厂》无限报错解决方法
- 交错战线原始交易所推荐角色一览
- 战锤40K星际战士2战术职业介绍|战术职业技能效果一览