小程序缓存

525 阅读1分钟

wx.setStorageSync

将数据存储在本地缓存中指定的 key 中。会覆盖掉原来该 key 对应的内容。除非用户主动删除或因存储空间原因被系统清理,否则数据都一直可用。单个 key 允许存储的最大数据长度为 1MB,所有数据存储上限为 10MB

wx.setStorage

将数据存储在本地缓存中指定的 key 中。会覆盖掉原来该 key 对应的内容。除非用户主动删除或因存储空间原因被系统清理,否则数据都一直可用。单个 key 允许存储的最大数据长度为 1MB,所有数据存储上限为 10MB

wx.revokeBufferURL

根据 URL 销毁存在内存中的数据

wx.removeStorageSync

wx.removeStorage 的同步版本

wx.removeStorage

从本地缓存中移除指定 key。缓存相关策略请查看 存储

any wx.getStorageSync

从本地缓存中同步获取指定 key 的内容。缓存相关策略请查看 存储

Object wx.getStorageInfoSync()

wx.getStorageInfo 的同步版本

wx.getStorageInfo

异步获取当前storage的相关信息。缓存相关策略请查看 存储

wx.getStorage(Object object)

从本地缓存中异步获取指定 key 的内容。缓存相关策略请查看 存储

wx.createBufferURL(ArrayBuffer|TypedArray buffer)

根据传入的 buffer 创建一个唯一的 URL 存在内存中

wx.clearStorageSync()

wx.clearStorage 的同步版本

wx.clearStorage(Object object)

清理本地数据缓存。缓存相关策略请查看 存储

存值

<input class="put" placeholder="请输入用户名"  bindinput="bindKeyInput"/>
<input type="password" name="" id="" class="put" placeholder="请输入密码" bindinput="passWord"/>
<button catchtap="cun">点我存</button>

js部分

Page({

  /**
   * 页面的初始数据
   */
  data: {
  inputVal:'',
  passWord:'',
  },
  passWord:function(e){
    let { detail:{value} }= e;
    this.setData({
      passWord:value
    })
  },
  bindKeyInput:function(e){
  let { detail:{value} }= e;
  this.setData({
    inputVal:value
  })
  },
  cun:function(){
  wx.setStorageSync('username', this.data.inputVal)
  wx.setStorageSync('passWord', this.data.passWord)
  },