kam*_*lav 4 indexeddb typescript angular
我已经尝试下面的代码来获取indexedDb配额存储信息
navigator.webkitTemporaryStorage.queryUsageAndQuota (
function(usedBytes, grantedBytes) {
console.log('we are using ', usedBytes, ' of ', grantedBytes, 'bytes');
},
function(e) { console.log('Error', e); }
);
Run Code Online (Sandbox Code Playgroud)
它不起作用,并出现以下错误。
类型“ Navigator”上不存在属性“ webkitTemporaryStorage”。
谁能提供在打字稿中获取indexedDb配额存储信息的解决方案?
问题在于缺少TypeScript输入。您可以考虑这个答案。
为了解决这个问题,一种解决方案是声明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); }
);
Run Code Online (Sandbox Code Playgroud)
另一种方法是扩展Navigator的界面
interface Navigator {
webkitTemporaryStorage: {
queryUsageAndQuota ;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
770 次 |
| 最近记录: |