获取indexedDb配额存储信息 [英] get indexedDb quota storage information

查看:93
本文介绍了获取indexedDb配额存储信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试下面的代码来获取indexedDb配额存储信息

I have tried below code to get indexedDb quota storage information

navigator.webkitTemporaryStorage.queryUsageAndQuota ( 
function(usedBytes, grantedBytes) {  
    console.log('we are using ', usedBytes, ' of ', grantedBytes, 'bytes');
}, 
function(e) { console.log('Error', e);  }
); 

它不起作用,并出现以下错误.

It is not working and giving the following error.

类型"Navigator"上不存在属性"webkitTemporaryStorage".

Property 'webkitTemporaryStorage' does not exist on type 'Navigator'.

任何人都可以提供解决方案来获取打字稿中的indexdDb配额存储信息吗?

Can anyone provide solution for getting indexedDb quota storage information in typescript?

推荐答案

问题出在缺少TypeScript输入.您可以考虑答案.

The problem lays in missing TypeScript typing. You can consider this answer.

要解决此问题,一种解决方案是声明类型为any的变量:

To solve the issue, one solution is to declare the variable of type any:

let nav: any = navigator;
nav.webkitTemporaryStorage.queryUsageAndQuota ( 
function(usedBytes, grantedBytes) {  
    console.log('we are using ', usedBytes, ' of ', grantedBytes, 'bytes');
}, 
function(e) { console.log('Error', e);  }
); 

另一种方法是扩展Navigator的界面

Another way is to extend the interface of Navigator

interface Navigator {
    webkitTemporaryStorage: {
        queryUsageAndQuota ;
    }
}

这篇关于获取indexedDb配额存储信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆