小程序數據緩存localStorage


存儲:wx.setStorageSync('storage', this.data.storage)

獲取:

that = this; 
wx.getStorage({
      key: 'storage',
      success: function(res){
        // success
        that.setData({
          storage:res.data
        })
      }
    })

 

==============================================================

index的js:

//index.js
//獲取應用實例
var app = getApp()
Page({
  data: {
    storage:''
  },
  onLoad: function () {
    var that = this

  //獲取輸入值
  getInput:function(e){
    this.setData({
      storage:e.detail.value
    })
  },
  //存儲輸入值
  saveInput:function(){
    wx.setStorageSync('storage', this.data.storage)
  }

})

跳轉頁面的js:

var app = getApp();
var that;  
Page( {  
  data: {    
    storage:''
  },  
  onLoad: function(options) {  
    that = this; 
    //獲取存儲信息
    wx.getStorage({
      key: 'storage',
      success: function(res){
        // success
        that.setData({
          storage:res.data
        })
      }
    })
  }

})  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM