国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > JavaScript > 正文

微信小程序 Storage API實(shí)例詳解

2019-11-20 08:49:50
字體:
供稿:網(wǎng)友

其實(shí)這個(gè)存儲(chǔ)在新建Demo的時(shí)候就已經(jīng)用到了就是存儲(chǔ)就是那個(gè)logs日志,數(shù)據(jù)存儲(chǔ)主要分為同步和異步

異步存儲(chǔ)方法:

存數(shù)據(jù)

wx.setStorage(object) 相同key會(huì)覆蓋,可寫回調(diào)方法

獲取方法:

wx.getStorage(object)

清除方法:

wx.clearStorage()里面可以寫回調(diào)函數(shù) 成功,失敗,完成

同步存儲(chǔ)方法:

存數(shù)據(jù) 相同key會(huì)覆蓋

wx.setStorageSync(key,data)

讀數(shù)據(jù)

wx.getStorageSync(key) 存儲(chǔ)是指定的key

清除數(shù)據(jù)

wx.clearStorageSync() 不可寫回調(diào)方法

wxml

<!--動(dòng)態(tài)獲取數(shù)據(jù)--><text>{{storageContent}}</text><!--存--><button type="primary" bindtap="listenerStorageSave">storage存儲(chǔ)信息會(huì)在text上顯示</button><!--取--><button type="primary" bindtap="listenerStorageGet">獲取storage存儲(chǔ)的信息</button><!--清--><button type="warn" bindtap="listenerStorageClear">清楚異步存儲(chǔ)數(shù)據(jù)</button><text>{{storageSyncContent}}</text><button type="primary" bindtap="listenerStorageSyncSave">storageSync存儲(chǔ)信息會(huì)在text上顯示</button><button type="primary" bindtap="listenerStorageSyncGet">獲取storageSync存儲(chǔ)信息</button><button type="warn" bindtap="listenerStorageSyncClear">清除同步存儲(chǔ)數(shù)據(jù)</button>

js

Page({ data:{  // text:"這是一個(gè)頁(yè)面"  storageContent: '',  storageSyncContent: '' }, onLoad:function(options){  // 頁(yè)面初始化 options為頁(yè)面跳轉(zhuǎn)所帶來的參數(shù) }, /**  * 異步存儲(chǔ)  */ listenerStorageSave: function() {  //以鍵值對(duì)的形式存儲(chǔ) 傳進(jìn)去的是個(gè)對(duì)象  wx.setStorage({   key: 'key',   data: '我是storeage異步存儲(chǔ)的信息',   success: function(res) {    console.log(res)   }  }) }, /**  * 異步取信息  */ listenerStorageGet: function() {  var that = this;  wx.getStorage({   //獲取數(shù)據(jù)的key   key: 'key',   success: function(res) {    console.log(res)    that.setData({     //     storageContent: res.data    })   },   /**    * 失敗會(huì)調(diào)用    */   fail: function(res) {    console.log(res)   }  }) }, /**  * 清除數(shù)據(jù)  */ listenerStorageClear: function() {  var that = this;  wx.clearStorage({   success: function(res) {    that.setData({     storageContent: ''    })   }  }) }, /**  * 數(shù)據(jù)同步存儲(chǔ)  */ listenerStorageSyncSave: function() {  wx.setStorageSync('key', '我是同步存儲(chǔ)的數(shù)據(jù)') }, /**  * 數(shù)據(jù)同步獲取  */ listenerStorageSyncGet: function() {  // var that = this;  var value = wx.getStorageSync('key')  this.setData({   storageSyncContent: value  }) }, /**  * 清除同步存儲(chǔ)數(shù)據(jù)  */ listenerStorageSyncClear: function() {  wx.clearStorageSync() }, onReady:function(){  // 頁(yè)面渲染完成 }, onShow:function(){  // 頁(yè)面顯示 }, onHide:function(){  // 頁(yè)面隱藏 }, onUnload:function(){  // 頁(yè)面關(guān)閉 }})

感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 密云县| 清徐县| 大兴区| 寿阳县| 平远县| 岗巴县| 白沙| 文成县| 微博| 镇平县| 屯留县| 辽中县| 镶黄旗| 霍邱县| 集安市| 湘潭市| 嵊州市| 娱乐| 乌拉特中旗| 手游| 金平| 灌阳县| 岑巩县| 古交市| 淮滨县| 浪卡子县| 敦化市| 嘉禾县| 贺州市| 奉节县| 津南区| 抚州市| 会同县| 康马县| 苏尼特左旗| 正定县| 泽州县| 栖霞市| 祁阳县| 抚宁县| 芦溪县|