Small micro-channel program data cache

Small micro-channel program data cache

Micro-channel official document describes link: https://developers.weixin.qq.com/miniprogram/dev/api/storage/wx.getStorage.html

 

  • And comparing the browser cache

    • Browser:  

      • localstorage (unless you manually cleared, or permanently stored locally)

      • sessionstorage (valid only in the current session, close the browser page or after clearing)  

    • Applets

      • storage

  • Role: is used to cache data

  • use:

    • storage

      • Asynchronous memory

        wx.setStorage({
        key: '',
        data: ''
        })
      • Synchronous storage

        wx.setStorageSync(key, data)
    • The value

      • Asynchronous Value

        wx.getStorage({
        key: '',
        success: res => {
        console.log(res.data)
        }
        })
      • Synchronization values

        let res = wx.getStorageSync(key)
    • Remove

      • Asynchronous Clear

        // clear the contents of the specified key in 
        wx.removeStorage ({
        key: '',
        Success: RES => { the console.log (res.data) } }) // clear all Storage wx.clearStorage ()




      • Synchronous Clear

        // Clear contents of the specified key in 
        wx.removeStorageSync (key)
        // remove all Storage
        wx.clearStorageSync ()
    • to sum up:

      • localstorage user applet storage with the browser similar, can understand the argument

      • note:

        • localstorage can only store strings

        • You may be stored in any type of data object storage array ,,, like.

 

Guess you like

Origin www.cnblogs.com/KoBe-bk/p/11465354.html