微信小程序开发(一)--数据存储

二. 同步存储


(1)wx.setStorageSync(KEY,DATA)

    将 data 存储在本地缓存中指定的 key 中,会覆盖掉原来该 key 对应的内容,这是一个同步接口。
wx.setStorageSync('key', 'value')

(2)wx.getStorageSync(KEY)

    从本地缓存中同步获取指定 key 对应的内容。
wx.getStorageSync('key')

三. 数据删除
(1)wx.removeStorage(OBJECT)

    从本地缓存中异步移除指定 key 。
wx.removeStorage({
  key: 'key',
  success: function(res) {
    console.log(res.data)
  },
  fail: function(res) {
    console.log(res.data)
  },
  complete: function(res) {
    console.log(res.data)
  }
})

(2) wx.removeStorageSync(KEY)

  从本地缓存中同步移除指定 key 。
wx.removeStorageSync('key')

(3) wx.clearStorage()

    清理本地数据缓存。
wx.clearStorage()

(4) wx.clearStorageSync()

同步清理本地数据缓存
wx.clearStorageSync()

你可能感兴趣的:(微信小程序)