我正在使用 Dexie 访问闪存卡制造商项目上的 IndexedDB。我可以按预期操作数据库,如果我关闭并重新打开浏览器,它会保留在数据库中,但通常当我在几天没有处理该项目后打开该项目时,我放入数据库中的存储数据是“不再有了。
我做了一些研究,发现我需要使数据库持久化,但我不知道如何做到这一点。
我几乎已将 Dexie Storage Manager 页面中的推荐代码复制到主页 index.js 的 onLoad 函数中。这是相关代码:
//When the page loads, display the decks in ul on the webpage.
window.addEventListener('load', onLoad);
async function onLoad() {
//Check how much data is available.
showEstimatedQuota();
//Make sure the storage is persistent.
isStoragePersisted().then(async isPersisted => {
if (isPersisted) {
console.log(":) Storage is successfully persisted.");
} else {
console.log(":( Storage is not persisted.");
console.log("Trying to persist..:");
if (await persist()) {
console.log(":) We successfully turned the storage to …Run Code Online (Sandbox Code Playgroud)