安装

npm install localforage

在vue工程中使用

引入

import localforage from 'localforage/dist/localforage.js'

创建多个实例仓库

import Vue from 'vue'
Vue.prototype.localforage = localforage
// 患者详情缓存数据库
const metaTemplateListDb = localforage.createInstance({
  name: 'metaTemplateListDb',
  storeName: `metaDataDbStore`
})
Vue.prototype.$metaTemplateListDb = metaTemplateListDb

// 字段树 缓存数据库 const treeTemplateListDb = localforage.createInstance({ name: 'treeTemplateListDb', storeName: treeDataDbStore }) Vue.prototype.$treeTemplateListDb = treeTemplateListDb

// 历史记录 缓存数据库 const historyRecordDb = localforage.createInstance({ name: 'historyRecordDb', storeName: historyRecordDbStore }) Vue.prototype.$historyRecordDb = historyRecordDb

使用
localforagegetItemsetItem是支持Promise语法的

async getDetailTemplateHandle(isSum) {
  const metaTemplateListDb = this.$metaTemplateListDb
  await metaTemplateListDb.setItem(`key`, [1]) // 设置
  const res = await this.$metaTemplateListDb.getItem(`key`)// 获取
}
或
this.$metaTemplateListDb.getItem(`key`).then(res => {
   console.log(res)
})              

文档:localforage中文文档