缓存数据-uni.setStorage()

  1. //获取的token数据
  2. let token = res.data
  3. uni.setStorage({
  4. key: 'token',
  5. data: token,
  6. success() {
  7. console.log('token本地缓存成功');
  8. }
  9. })

同步方法

uni.setStorageSync('token',token)

获取缓存的数据-uni.getStorage(OBJECT)

  1. uni.getStorage({
  2. key: 'token',
  3. success: res => {
  4. this.token = res.data
  5. }
  6. })

同步方法:

this.token = uni.getStorageSync('token')

从本地缓存中异步移除指定 key-uni.removeStorage(OBJECT)

  1. uni.removeStorage({
  2. key: 'storage_key',
  3. success: function (res) {
  4. console.log('success');
  5. }
  6. });

同步方法:uni.removeStorageSync('storage_key');


清理本地数据缓存-uni.clearStorage()
uni.clearStorage();

同步方法:uni.clearStorageSync();