实现方法很简单,使用前把所有localStorage的key和值存储到两个数组,plus.cache.clear清除完成后利用循环重新写入即可
function plusReady() {
var key = []
var key_ = []
for (let i = 0; i < localStorage.length; i++) {
key.push(localStorage.key(i)) //获取所有localStorage的key
key_.push(localStorage.getItem(localStorage.key(i))) //获取所有localStorage的值
length = localStorage.length //获取所有localStorage数量
if (i == localStorage.length - 1) {
plus.nativeUI.confirm("确定清除缓存数据?", function (e) {
if (e.index == 0) {
plus.cache.clear(function () { });//清除缓存
plus.nativeUI.toast('已清除缓存');
for (let a = 0; a < length; a++) {
localStorage.setItem(key[a], key_[a]) //清除完毕后利用重新写入localStorage
}
}
}, "清除缓存数据", ["确定", "取消"]);
}
}
}
if (window.plus) {
plusReady();
} else {
document.addEventListener('plusready', plusReady, false);
}
0 个评论
要回复文章请先登录或注册