微信小程序中怎么存setStorage


在js中存入setStorage,key是你的鍵,data是你的值

    wx.setStorage({
      key: 'mm',
      data: 1,
    })
    // 獲取getStorageSync的方式
 
    console.log(wx.getStorageSync('mm'))  #獲取的方式
 
 
 
接下來是或數據中的存取 ,其實是一樣的啦,直接上代碼
js文件中代碼。
 
  onLoad: function (options) {
    var thit = this
    wx.request({ //請求地址
      url: 'http://127.0.0.1:8000/api/index/',
      method: 'get',
      // data:{},//沒有數據可以不寫 
      header: { //請求頭
        'content-type': 'application/json'
        // "Content-Type": "application/x-www-form-urlencoded"
      },
      //如果在sucess直接寫this就變成了wx.request()的this了
      success: function (res) {
        // res.data相當於ajax里面的data,為后台返回的數據
        //打印后台返回的數據
        console.log(res.data.message)
        //直接把后台返回的數據 賦值給names 就可以直接調用names了
        thit.setData({
          names: res.data.message,
          names1: res.data.message1,  //返回的第二條數據
          names2: res.data.message2  // 第三條數據
        })

    //  存入setStorage
        wx.setStorage({
          key: 'kkk',
          data: res.data.message2,   //存第三條數據
        })
        //查看方式  定義一個變量
           var eee = wx.getStorageSync('kkk')
        console.log(eee)
      }
    })
      },


免責聲明!

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



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