uni-app读取html缓存,uni-app同步缓存值 设置 读取 删除(示例代码)
A頁面
去login頁面
msg : [
\'uniapp行業峰會頻頻亮相開發者反響熱烈\',
\'DCloud完成B2輪融資,uni-app震撼發布\',
\'36氪熱文榜推薦、CSDN公號推薦 DCloud\'
]
gotologin(){
uni.setStorageSync(\'storage_key\', \'hello\');//存儲一個字符傳值
//存儲數組前,將數組轉為字符串
uni.setStorageSync(\'mykeymas\',JSON.stringify(this.msg))
//跳轉頁面(不會關閉當前頁)
uni.navigateTo({
url:"/pages/login/login"
})
}
B頁面讀取值
//監聽頁面加載.其參數為上個頁面傳遞的數據,參數類型為Object(用于頁面傳參)此處沒有用
onLoad(option){
const value = uni.getStorageSync(\'storage_key\');
console.log(\'獲取的key\',value)
//將字符串轉為對象
let con= JSON.parse(uni.getStorageSync(\'mykeymas\'));
console.log(\'獲取的mykeymas\',con)
},
B頁面讀取所有的key值
獲取所有key
methods:{
allgetkey(){
const res = uni.getStorageInfoSync();
console.log("所有多少個key",res.keys);
console.log("現在key所占值的大小",res.currentSize);
console.log("key最多可以裝",res.limitSize);
},
}
B頁面清除某一個特定的key
清除一個key值
methods:{
clearKey(){
uni.removeStorageSync(\'storage_key\');
}
}
B頁面清除所有的key
清除所有的key值
methods:{
clearAllKey(){
uni.clearStorageSync();
}
}
這些都是同步操作,還有異步的,我沒有寫,以后有機會再寫吧
uni.setStorageSync(\'storage_key\', \'hello\'); 設置
uni.getStorageSync(\'storage_key\'); 讀取
const res = uni.getStorageInfoSync(); 讀取所有的值
uni.removeStorageSync(\'storage_key\'); 清除某一個特定的key
uni.clearStorageSync(); 清除所有的key
將 data 存儲在本地緩存中指定的 key 中,會覆蓋掉原來該 key 對應的內容,這是一個同步接口。
在h5中它是存儲在localStorage中的
微信小程序是在Storage中的
總結
以上是生活随笔為你收集整理的uni-app读取html缓存,uni-app同步缓存值 设置 读取 删除(示例代码)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 大竹中学2021高考成绩查询,四川大竹中
- 下一篇: 长安大学微型计算机原理与接口技术答案,长