uni app检测缓存并清理缓存

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)
							}
						}
					})
			 },
			}
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值