最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

微信小程序 Storage API實例詳解

 更新時間:2016年10月02日 09:38:16   作者:順子_RTFSC  
這篇文章主要介紹了微信小程序 Storage API實例詳解的相關(guān)資料,需要的朋友可以參考下

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

異步存儲方法:

存數(shù)據(jù)

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

獲取方法:

wx.getStorage(object)

清除方法:

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

同步存儲方法:

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

wx.setStorageSync(key,data)

讀數(shù)據(jù)

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

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

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

wxml

<!--動態(tài)獲取數(shù)據(jù)-->
<text>{{storageContent}}</text>
<!--存-->
<button type="primary" bindtap="listenerStorageSave">storage存儲信息會在text上顯示</button>
<!--取-->
<button type="primary" bindtap="listenerStorageGet">獲取storage存儲的信息</button>
<!--清-->
<button type="warn" bindtap="listenerStorageClear">清楚異步存儲數(shù)據(jù)</button>


<text>{{storageSyncContent}}</text>
<button type="primary" bindtap="listenerStorageSyncSave">storageSync存儲信息會在text上顯示</button>
<button type="primary" bindtap="listenerStorageSyncGet">獲取storageSync存儲信息</button>
<button type="warn" bindtap="listenerStorageSyncClear">清除同步存儲數(shù)據(jù)</button>

js

Page({
 data:{
  // text:"這是一個頁面"
  storageContent: '',
  storageSyncContent: ''
 },
 onLoad:function(options){
  // 頁面初始化 options為頁面跳轉(zhuǎn)所帶來的參數(shù)
 },
 /**
  * 異步存儲
  */
 listenerStorageSave: function() {
  //以鍵值對的形式存儲 傳進(jìn)去的是個對象
  wx.setStorage({
   key: 'key',
   data: '我是storeage異步存儲的信息',
   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
    })
   },
   /**
    * 失敗會調(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ù)同步存儲
  */
 listenerStorageSyncSave: function() {
  wx.setStorageSync('key', '我是同步存儲的數(shù)據(jù)')
 },

 /**
  * 數(shù)據(jù)同步獲取
  */
 listenerStorageSyncGet: function() {
  // var that = this;
  var value = wx.getStorageSync('key')
  this.setData({
   storageSyncContent: value
  })
 },

 /**
  * 清除同步存儲數(shù)據(jù)
  */
 listenerStorageSyncClear: function() {
  wx.clearStorageSync()
 },

 onReady:function(){
  // 頁面渲染完成
 },
 onShow:function(){
  // 頁面顯示
 },
 onHide:function(){
  // 頁面隱藏
 },
 onUnload:function(){
  // 頁面關(guān)閉
 }
})

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

相關(guān)文章

最新評論

沐川县| 南丹县| 汝阳县| 西华县| 精河县| 武定县| 蒙阴县| 莒南县| 七台河市| 延寿县| 烟台市| 正安县| 无棣县| 富蕴县| 资溪县| 雷波县| 襄垣县| 靖边县| 宜黄县| 仁布县| 抚顺县| 瑞金市| 朝阳市| 雅安市| 金湖县| 哈尔滨市| 白水县| 黎城县| 日土县| 武川县| 松潘县| 日喀则市| 呈贡县| 秦皇岛市| 台安县| 田东县| 舞阳县| 古浪县| 偏关县| 正安县| 礼泉县|