多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
> 实现如图所例 > ![](https://img.kancloud.cn/71/31/713136021e9a4ceb4073cef64f11f6b2_788x480.png) ## 示例代码 ~~~ <template> <view class="content"> <view>应用缓存:{{storageSize}}</view> <button type="default" @tap="clearStorage">清除缓存</button> </view> </template> <script> export default { data() { return { storageSize : '' } }, onLoad() { this.getStorageSize(); }, methods:{ 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:'清除成功' }) } } }) } } } </script> ~~~