uni.setStorageSync(KEY,DATA)
將 data 存儲在本地緩存中指定的 key 中,如果有多個key相同,下面的會覆蓋掉原上面的該 key 對應的內容,這是一個同步接口。數據可以是字符串,可以是數組。
<script setup>uni.setStorageSync('storage_key', 'hello');uni.setStorageSync('storage_key', 'Jim');uni.setStorageSync('attrs', [1,2,3]);
</script>
H5查看緩存
微信開發者平臺查看本地緩存
?
獲取緩存
let myname = uni.getStorageInfoSync('name')console.log("myname:"+myname)
//根據key清除緩存
function remove(){uni.removeStorageSync('name')
}
//清除所有緩存
function clear(){uni.clearStorageSync()
}
?以上存取緩存使用的是同步的方式,uni-app也提供了異步存取緩存的方法,更多緩存的使用方法詳見官方文檔:uni.setStorage(OBJECT) @setstorage | uni-app官網