- uni.setStorage()">缓存数据-uni.setStorage()
- uni.getStorage(OBJECT)">获取缓存的数据-uni.getStorage(OBJECT)
- uni.removeStorage(OBJECT)">从本地缓存中异步移除指定 key-uni.removeStorage(OBJECT)
- uni.clearStorage()
uni.clearStorage();
">
清理本地数据缓存-uni.clearStorage()uni.clearStorage();
缓存数据-uni.setStorage()
//获取的token数据
let token = res.data
uni.setStorage({
key: 'token',
data: token,
success() {
console.log('token本地缓存成功');
}
})
同步方法
uni.setStorageSync('token',token)
获取缓存的数据-uni.getStorage(OBJECT)
uni.getStorage({
key: 'token',
success: res => {
this.token = res.data
}
})
同步方法:
this.token = uni.getStorageSync('token')
从本地缓存中异步移除指定 key-uni.removeStorage(OBJECT)
uni.removeStorage({
key: 'storage_key',
success: function (res) {
console.log('success');
}
});
同步方法:uni.removeStorageSync('storage_key');
清理本地数据缓存-uni.clearStorage()
uni.clearStorage();
同步方法:uni.clearStorageSync();