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

嘉鱼网站建设哪家专业电商代运营一般收多少服务费

嘉鱼网站建设哪家专业,电商代运营一般收多少服务费,wordpress图片剪裁插件,微网站建设对微网站进行策划一、什么是 localForage 当我们的存储量比较大的时候,我们一定会想到我们的 indexedDB,让我们在浏览器中也可以 使用数据库这种形式来玩转本地化存储,然而 indexedDB 的使用是比较繁琐而复杂的, 有一定的学习成本,但 …

一、什么是 localForage

当我们的存储量比较大的时候,我们一定会想到我们的 indexedDB,让我们在浏览器中也可以
使用数据库这种形式来玩转本地化存储,然而 indexedDB 的使用是比较繁琐而复杂的,
有一定的学习成本,但 localForage 的出现几乎抹平了这个缺陷,让我们轻松无负担的在
浏览器中使用 indexedDB。localStorage如果存储内容多的话会消耗内存空间,会导致页面变卡。
那么 IndexedDB 存储量过多的话会导致页面变卡吗?不会有太大影响,因为 IndexedDB 的读取和存储都是异步的,不会阻塞浏览器进程。IndexedDB 的储存空间比LocalStorage 大得多,一般可达到500M,甚至没有上限。而localForage 是基于 indexedDB 封装的库,通过它我们可以简化 IndexedDB 的使用。

若浏览器不支持 IndexedDB 或 WebSQL,则使用 localStorage。在所有主流浏览器中都可用:Chrome,Firefox,IE 和 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 '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://www.dtcms.com/wzjs/333520.html

相关文章:

  • 酒泉哪家公司可以做网站站长之家 seo查询
  • 企业网站开发前后台模块设计百度网盘官方网站
  • 苏州网站建站公司百青藤广告联盟
  • 做网站头文件广州谷歌优化
  • 深圳网站建设服务哪家专业网站展示型推广
  • 自考本科条件站长工具seo查询
  • 社交网站开发公司凡科建站手机版登录
  • wordpress腾讯云邮件发送站内seo优化
  • 公司建设网站网站建设的一般步骤
  • 潍坊网站建设优化深圳市企业网站seo
  • 贺兰网站建设京东关键词优化技巧
  • 电脑做网页用什么软件中山口碑seo推广
  • 一号网站建设中央常委成员名单
  • 电商网站建设平台刷网站百度关键词软件
  • 专业建站策划网络事件营销案例
  • 比特币交易网站可以做空吗个人网页模板
  • 市场营销计划书模板济南seo外包服务
  • 景观设计师证怎么考南昌seo教程
  • 做seo网站app推广方法
  • 品牌网站建设优化公司口碑营销例子
  • 重庆高端网站建设佛山网站快速排名提升
  • 网站开发费怎么做会计分录北京seo服务商找行者seo
  • 衡阳衡南网站建设搜索引擎优化课程
  • 怎么做网站信息网络舆情监测与研判
  • 网站更换贵阳网络推广排名
  • 美国免费网站空间seo专员工资一般多少
  • 网站不收录怎么解决联赛积分榜排名
  • 北京网站推广站长工具是干嘛的
  • 如何在线制作印章朝阳seo搜索引擎
  • 清新网站模板可以免费发广告的网站