uni app检测缓存并清理缓存
app端需要做清理缓存功能

1,组件里面的事件
清除缓存 {{storageSize}}
2,script里面的js部分,清除完后跳到登录页面
data() {return {storageSize:'0M',}},
onLoad() {this.getStorageSize()//获取缓存},methods: {//获取app的缓存getStorageSize:function(){let that = this;uni.getStorageInfo({success(res) {//console.log(res.keys);//console.log(res.limitSize);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';}}})},//删除 缓存clearStorage:function (){let that = this;uni.showModal({title:'提示',content:'确定清除缓存吗?',confirmText:'立即清除',success(res) {if(res.confirm){uni.clearStorageSync();//重新获取并显示清除后的缓存大小that.getStorageSize();uni.showToast({title:'清除成功',icon:'none'})//清除完后跳到登录页面setTimeout(()=>{uni.redirectTo({url:'/pages/login/login',animationType: 'pop-in',animationDuration: 200})},1300)}}})},}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
