uniapp本地存储
需要注意:vue的本地存储方式, 小程序在浏览器测试时也可以实现, 但是在真机运行时不能实现
一.储存
uni.setStorage(object)
- object的参数
uni.setStorageSync(key, data)
try{
uni.setStorageSync('token', '123456')
} catch (e){
//错误
}
二.获取
uni.getStorage(OBJECT)
从本地存储中异步获取对应可以对应的内容
uni.getStorageSync(key)
从本地缓存中同步获取指定key对应的内容
try {
const value = uni.getStorageSync("token");
if(value) {
console.log(value)
}
} catch(e){
//错误
}
三.移除
uni.removeStorage(object)
从本地缓存中异步移除指定key
uni.removeStorageSync(key)
从本地缓存中同步移除指定key
try {
uni.removeStorageSync('storage_key')
} catch(e){
//错误
}