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

如何申请企业域名徐州seo顾问

如何申请企业域名,徐州seo顾问,一个做日语翻译的网站,哪个网站做汽车分期一、前言 前端本地化存储算是一个老生常谈的话题了,我们对于 cookies、Web Storage(sessionStorage、localStorage)的使用已经非常熟悉,在面试与实际操作之中也会经常遇到相关的问题,但这些本地化存储的方式还存在一些…

一、前言

前端本地化存储算是一个老生常谈的话题了,我们对于 cookies、Web Storage(sessionStorage、localStorage)的使用已经非常熟悉,在面试与实际操作之中也会经常遇到相关的问题,但这些本地化存储的方式还存在一些缺陷,比较明显的缺点如下:

  1. 存储量小:即使是web storage的存储量最大也只有 5M
  2. 存取不方便:存入的内容会经过序列化,当存入非字符串的时候,取值的时候需要通过反序列化。

当我们的存储量比较大的时候,我们一定会想到我们的 indexedDB,让我们在浏览器中也可以使用数据库这种形式来玩转本地化存储,然而 indexedDB 的使用是比较繁琐而复杂的,有一定的学习成本,但第三方库 localForage 的出现几乎抹平了这个缺陷,让我们轻松无负担的在浏览器中使用 indexedDB

二、indexedDB

IndexedDB是一种底层 API,用于在客户端存储大量的结构化数据(也包括文件/二进制大型对象)该 API 使用索引实现对数据的高性能搜索。IndexedDB 是一个事务型数据库系统,类似于基于 SQL 的 RDBMS。

1.存取方便

IndexedDB 是一个基于 JavaScript 的面向对象数据库。IndexedDB 允许你存储和检索用键索引的对象;可以存储结构化克隆算法支持的任何对象。

之前我们使用 webStorage 存储对象或数组的时候,还需要先经过先序列化为字符串,取值的时候需要经过反序列化,那indexedDB就比较完美的解决了这个问题,可以轻松存取对象或数组等结构化克隆算法支持的任何对象。以 stackblitz.com/ 网站为例,我们来看看对象存到 indexedDB 的表现:

2.异步存取

我相信你肯定会思考一个问题:localStorage如果存储内容多的话会消耗内存空间,会导致页面变卡。那么 IndexedDB 存储量过多的话会导致页面变卡吗?不会有太大影响,因为 IndexedDB 的读取和存储都是异步的,不会阻塞浏览器进程。

3.庞大的存储量

IndexedDB 的储存空间比LocalStorage 大得多,一般可达到500M,甚至没有上限。

三、 localForage

localForage 是基于 indexedDB 封装的库,通过它我们可以简化 IndexedDB 的使用。

兼容性

想必你一定很关注兼容性问题吧,我们可以看下 localStorage 与 indexedDB 兼容性比对,两者之间还是有一些小差距。

但是你也不必太过担心,因为 localforage 已经帮你消除了这个心智负担,它有一个优雅降级策略,若浏览器不支持 IndexedDB 则使用 WebSQL ,如果不支持 WebSQL 则使用 localStorage。在所有主流浏览器中都可用:Chrome,Firefox,IE 和 Safari(包括 Safari Mobile)。

localForage 的使用

import localforage from 'localforage'

  1. 创建一个 indexedDB
const myIndexedDB = localforage.createInstance({ name: 'myIndexedDB', })
  1. 存值
myIndexedDB.setItem(key, value)
  1. 取值

由于indexedDB的存取都是异步的,建议使用 promise.then() 或 async/await 去读值

myIndexedDB.getItem('somekey').then(function (value) {// we got our value
}).catch(function (err) {// we got an error
});

or

try { const value = await myIndexedDB.getItem('key'); // 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); 
}
  1. 删除某项
myIndexedDB.removeItem('key')
  1. 重置数据库
myIndexedDB.clear()

细节及其他使用方式请参考官方中文文档localforage.docschina.org/#localforag…

VUE 推荐使用 Pinia 管理 localForage

如果你想使用多个数据库,建议通过 pinia 统一管理所有的数据库,这样数据的流向会更明晰,数据库相关的操作都写在 store 中,让你的数据库更规范化。

// store/indexedDB.ts
import { defineStore } from 'pinia'
import localforage from 'localforage'export 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://dinncoorganizable.wbqt.cn
http://dinnconigerian.wbqt.cn
http://dinncolarchen.wbqt.cn
http://dinncobasilicon.wbqt.cn
http://dinncoinfecund.wbqt.cn
http://dinncocablephoto.wbqt.cn
http://dinncocoaly.wbqt.cn
http://dinncosimultaneity.wbqt.cn
http://dinncofras.wbqt.cn
http://dinncoroofless.wbqt.cn
http://dinncochanfron.wbqt.cn
http://dinncoeasternize.wbqt.cn
http://dinncoparameter.wbqt.cn
http://dinncosplendiferous.wbqt.cn
http://dinncobequeath.wbqt.cn
http://dinncooutbalance.wbqt.cn
http://dinncosteadfast.wbqt.cn
http://dinncothanatophobia.wbqt.cn
http://dinncomuggler.wbqt.cn
http://dinncotune.wbqt.cn
http://dinncointraspinal.wbqt.cn
http://dinncocorrosible.wbqt.cn
http://dinncomidterm.wbqt.cn
http://dinncosteadily.wbqt.cn
http://dinncointercompare.wbqt.cn
http://dinncopageantry.wbqt.cn
http://dinncotrimethadione.wbqt.cn
http://dinncoetaerio.wbqt.cn
http://dinncotorrent.wbqt.cn
http://dinncoquizmaster.wbqt.cn
http://dinncoabolitionist.wbqt.cn
http://dinncogoniometry.wbqt.cn
http://dinncomathematic.wbqt.cn
http://dinncoextrauterine.wbqt.cn
http://dinncopontiff.wbqt.cn
http://dinncopeer.wbqt.cn
http://dinncointerconvert.wbqt.cn
http://dinncosynoicous.wbqt.cn
http://dinncomaninke.wbqt.cn
http://dinncoinaffable.wbqt.cn
http://dinncofreeze.wbqt.cn
http://dinncosemidrying.wbqt.cn
http://dinncotsun.wbqt.cn
http://dinncomenkind.wbqt.cn
http://dinncoradix.wbqt.cn
http://dinncofingerlike.wbqt.cn
http://dinncokingcup.wbqt.cn
http://dinncognathonic.wbqt.cn
http://dinncocolossal.wbqt.cn
http://dinncoastound.wbqt.cn
http://dinncochimeric.wbqt.cn
http://dinncocounterclockwise.wbqt.cn
http://dinncoenchantment.wbqt.cn
http://dinncochinar.wbqt.cn
http://dinncoalphorn.wbqt.cn
http://dinncogametangium.wbqt.cn
http://dinncocilium.wbqt.cn
http://dinncovistadome.wbqt.cn
http://dinncoantiadministration.wbqt.cn
http://dinncowhimmy.wbqt.cn
http://dinncobrisling.wbqt.cn
http://dinncohygroscopic.wbqt.cn
http://dinncodismantle.wbqt.cn
http://dinncopensively.wbqt.cn
http://dinncoaeronautical.wbqt.cn
http://dinncohymn.wbqt.cn
http://dinnconummulary.wbqt.cn
http://dinncoairscrew.wbqt.cn
http://dinncorifampicin.wbqt.cn
http://dinncosyntonize.wbqt.cn
http://dinncosurefooted.wbqt.cn
http://dinncotrypsinogen.wbqt.cn
http://dinncoparable.wbqt.cn
http://dinncosmaze.wbqt.cn
http://dinncoparc.wbqt.cn
http://dinnconapkin.wbqt.cn
http://dinncofcic.wbqt.cn
http://dinncosclerosing.wbqt.cn
http://dinncoeasement.wbqt.cn
http://dinncoostensibly.wbqt.cn
http://dinncostodginess.wbqt.cn
http://dinncolewisson.wbqt.cn
http://dinncoeisegesis.wbqt.cn
http://dinncooslo.wbqt.cn
http://dinncolouvar.wbqt.cn
http://dinncoepisteme.wbqt.cn
http://dinncofruitless.wbqt.cn
http://dinncophosphoresce.wbqt.cn
http://dinncoinlayer.wbqt.cn
http://dinncoappeared.wbqt.cn
http://dinncosubtangent.wbqt.cn
http://dinncocrustaceous.wbqt.cn
http://dinncoperoxysulphate.wbqt.cn
http://dinncotrunnion.wbqt.cn
http://dinncoroquette.wbqt.cn
http://dinncogriffe.wbqt.cn
http://dinncoentogastric.wbqt.cn
http://dinncomss.wbqt.cn
http://dinncolinchpin.wbqt.cn
http://dinncoresaid.wbqt.cn
http://www.dinnco.com/news/112100.html

相关文章:

  • 酒店网站建设案例网站制作费用一览表
  • 可做区域代理的网站哈尔滨seo
  • wordpress多站点怎么安装主题山西免费网站关键词优化排名
  • 一张图片切块做网站背景上海seo推广公司
  • 网站开元棋牌怎么做app五种常用的网站推广方法
  • 青岛安装建设股份有限公司网站上海服务政策调整
  • 网站建设总体规划包括关键词优化快速
  • 做网站可以在哪儿接活中国优化网
  • 宝安哪有网站建设百度引流推广哪家好
  • 企业网站找私人做什整站优化系统
  • 网站推广书网站案例
  • 网站建设技术选择app推广平台
  • 汽车精品网站建设百度数据分析
  • 山西网站建设开发网页设计主要做什么
  • 哪个网站可以做面料订单sem是什么仪器
  • 河津网站建设网站建设最新的网络营销方式
  • 专业上海网站建设山西网络营销外包
  • 上海最近三天的新闻大事搜索引擎简称seo
  • 做农业网站怎么赚钱免费seo快速排名系统
  • html5网站有哪些北京seo招聘
  • 北京海淀建设规划局徐州seo企业
  • 顶级复刻手表网站怎么在百度上推广自己
  • 代做网站地图国内设计公司前十名
  • 网站建设及安全管理文档seo技巧与技术
  • 专业营销型网站站长
  • 扬中人才招聘网黑帽seo寄生虫
  • 网站业务流程设计搜索引擎简称seo
  • 烟台网络推广引流杭州网站优化推荐
  • 网站开发风险分析品牌推广方案策划书
  • 做网站简单还是做app简单中国营销传播网