app需要做清除缓存功能
1,组件里面的事件
<view class="row" @click="clearStorage">
<view class="title">清除缓存</view>
<view class="right">
<view class="tis tell">{{storageSize}}</view>
<uni-icons type="arrowright" color="#C9C9C9" size="20"></uni-icons>
</view>
</view>
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)
}
}
})
},
}