【问题标题】:get indexedDb quota storage information获取 indexedDb 配额存储信息
【发布时间】:2018-05-11 16:57:56
【问题描述】:

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

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

它不工作并给出以下错误。

“Navigator”类型上不存在属性“webkitTemporaryStorage”。

谁能提供在 typescript 中获取 indexedDb 配额存储信息的解决方案?

【问题讨论】:

  • 您的代码正在运行!我将其复制并粘贴到浏览器控制台中。您收到的错误信息是什么?
  • 我没有得到。我在 typescript 中使用了这个代码并得到错误 Property 'webkitTemporaryStorage' does not exist on type 'Navigator'
  • 这是一个与 typeScript 中的类型有关的问题

标签: angular typescript indexeddb


【解决方案1】:

问题在于缺少 TypeScript 输入。你可以考虑这个answer

为了解决这个问题,一种解决方法是声明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的接口

interface Navigator {
    webkitTemporaryStorage: {
        queryUsageAndQuota ;
    }
}

【讨论】:

  • 不客气!不要忘记为答案投票:)
  • 嗨,我检查了我的 appdata 文件夹中的 indexeddb 大小。它只有 180kb。但是这段代码给出了 761194596 个字节。你能解释一下使用的字节是什么意思
  • 你可以看看here
猜你喜欢
  • 2023-04-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多