How to save setstorage in wechat applet


This article mainly introduces how to save setstorage in wechat applet. The example code is introduced in great detail, which has a certain reference learning value for everyone’s study or work. Friends in need can refer to it

Save setstorage in JS. Key is your key and data is your value

   key: 'mm',
   data: 1,
  //How to get getstoragesync
  How to get console.log (Wx. Getstoragesync ('mm '))

Next is the access to data or data. It’s actually the same. Code directly

Code in JS file

onLoad: function (options) {
  var thit = this
  Wx. Request ({// request address)
   url: '',
   method: 'get',
   //Data: {}, // no data can be written 
   Header: {// request header
    'content-type': 'application/json'
    // "Content-Type": "application/x-www-form-urlencoded"
   //If you write this directly in susess, it becomes this of Wx. Request()
   success: function (res) {
    // is equivalent to the data in Ajax, which is the data returned by the background
    //Print the data returned by the background
    //Directly assign the data returned by the background to names, then you can call names directly
     Names1: 1, // the second data returned
     Names2: 2 // the third data

  //Save to setstorage
     key: 'kkk',
     Data: 2, // save the third data
    //View mode defines a variable
      var eee = wx.getStorageSync('kkk')

The above is the whole content of this article, I hope to help you learn, and I hope you can support developer more.