当前位置: 首页 > news >正文

北京城乡建设集团网站沈阳网站设计制作公司

北京城乡建设集团网站,沈阳网站设计制作公司,wordpress目录图片,兰州优化网站推广一、什么是 localForage 当我们的存储量比较大的时候#xff0c;我们一定会想到我们的 indexedDB#xff0c;让我们在浏览器中也可以 使用数据库这种形式来玩转本地化存储#xff0c;然而 indexedDB 的使用是比较繁琐而复杂的#xff0c; 有一定的学习成本#xff0c;但 …一、什么是 localForage 当我们的存储量比较大的时候我们一定会想到我们的 indexedDB让我们在浏览器中也可以 使用数据库这种形式来玩转本地化存储然而 indexedDB 的使用是比较繁琐而复杂的 有一定的学习成本但 localForage 的出现几乎抹平了这个缺陷让我们轻松无负担的在 浏览器中使用 indexedDB。localStorage如果存储内容多的话会消耗内存空间会导致页面变卡。 那么 IndexedDB 存储量过多的话会导致页面变卡吗不会有太大影响因为 IndexedDB 的读取和存储都是异步的不会阻塞浏览器进程。IndexedDB 的储存空间比LocalStorage 大得多一般可达到500M甚至没有上限。而localForage 是基于 indexedDB 封装的库通过它我们可以简化 IndexedDB 的使用。 若浏览器不支持 IndexedDB 或 WebSQL则使用 localStorage。在所有主流浏览器中都可用ChromeFirefoxIE 和 Safari包括 Safari Mobile。 二、localForage 的使用 1安装和引入 npm install localforage import localforage from localforage 2、创建一个 indexedDB const myIndexedDB localforage.createInstance({name: myIndexedDB, }) 3、存储 myIndexedDB.setItem(key, value) 4、取值由于indexedDB的存取都是异步的建议使用 promise.then() 或 async/await 去读值 myIndexedDB.getItem(somekey).then(function (value) {// we got our value }).catch(function (err) {// we got an error }); 或者 try {const value await myIndexedDB.getItem(somekey);// This code runs once the value has been loaded// from the offline store.console.log(value); } catch (err) {// This code runs if there were any errors.console.log(err); } 5、删除 myIndexedDB.removeItem(somekey) 6、重置数据库 myIndexedDB.clear() VUE3 推荐使用 Pinia 管理 localForage // store/indexedDB.ts import { defineStore } from pinia import localforage from localforageexport const useIndexedDBStore defineStore(indexedDB, {state: () ({filesDB: localforage.createInstance({name: filesDB,}),usersDB: localforage.createInstance({name: usersDB,}),responseDB: localforage.createInstance({name: responseDB,}),}),actions: {async setfilesDB(key: string, value: any) {this.filesDB.setItem(key, value)},} }) 我们使用的时候就直接调用 store 中的方法 import { useIndexedDBStore } from /store/indexedDB const indexedDBStore useIndexedDBStore() const file1 {a: hello} indexedDBStore.setfilesDB(file1, file1) 《完》
http://www.zqtcl.cn/news/276520/

相关文章:

  • 小浣熊做单网站观看床做视频网站
  • 网站版面布局结构图门户网站要求
  • 网站左侧广告代码网站建设交接协议书
  • dedecms网站上传华为网络营销案例分析
  • wordpress搭建站点龙岗网站建设代理商
  • 做销售网站要多少钱建立网站的流程
  • 视频类网站如何做缓存网页设计框架怎么写
  • wordpress建站访问提示不安全网页加速器哪个最好用
  • 网博士自助建站系统下载毕业设计代做网站唯一
  • 江西网站建设优化服务营销软文范例大全100字
  • 图片类网站怎样做高并发专业做旗袍花的网站是什么网站
  • 我要建网站需要什么专业网站制作全包
  • 网站开发合同印花税自定义手机网站建设
  • 营销型网站开发流程制作网站需要钱吗
  • 提供有经验的网站建设百度识图识别
  • html手机网站怎么做湖南关键词优化品牌推荐
  • 网站定制开发收费标准是多少易语言如何做浏网站
  • 网站怎么做实名认证新手怎么开婚庆公司
  • .net做网站用什么技术网站优化排名方案
  • 电商网站备案流程网站移动端优化的重点有哪些
  • 数据需求 网站建设做qq空间的网站
  • 微信网站游戏网络规划设计师可以挂证吗
  • 有个做特价的购物网站网站建设与维护题库及答案
  • 长沙网站优化价格创意设计师个人网站
  • 滨河网站建设南京免费发布信息网站
  • 蓝色系列的网站邓砚谷电子商务网站建设
  • 德阳市住房和城乡建设局网站首页一个服务器可以建多少个网站
  • 建一个电商网站多少钱一起做网店货源app
  • 做网站用lunx代理记账 营销型网站
  • 凡客做网站怎么样WordPress分类目录 前100篇