清除缓存

clearStorage: function() {
let that = this;
uni.showModal({
title: '提示',
content: '确定清除缓存吗?',
confirmText: '立即清除',
success(res) {
if (res.confirm) {
uni.clearStorageSync();
//重新获取并显示清除后的缓存大小
that.getStorageSize();
uni.showToast({
title: '清除成功'
})
}
}
})
}

getStorageSize: function() {
let that = this;
uni.getStorageInfo({
success(res) {


let size = res.currentSize;
if (size < 1024) {
that.storageSize = size + ' B';
} else if (size / 1024 >= 1 && size / 1024 / 1024 < 1) {
that.storageSize = Math.floor(size / 1024 * 100) / 100 + ' KB';
} else if (size / 1024 / 1024 >= 1) {
that.storageSize = Math.floor(size / 1024 / 1024 * 100) / 100 + ' M';
}
}
})
},

posted on 2021-12-01 10:01  是慧慧呀  阅读(163)  评论(0)    收藏  举报

导航