IndexedDB 包装库 idb

原文链接: IndexedDB 包装库 idb

上一篇: win10 更新到2004 安装常用环境

下一篇: vue3 watch 数组

功能比较全的

https://github.com/jakearchibald/idb

只作为k-v存储简单使用的

https://github.com/jakearchibald/idb-keyval

使用很简单

Usage

set:

import { set } from 'idb-keyval';

set('hello', 'world');
set('foo', 'bar');

Since this is IDB-backed, you can store anything structured-clonable (numbers, arrays, objects, dates, blobs etc).

All methods return promises:

import { set } from 'idb-keyval';

set('hello', 'world')
  .then(() => console.log('It worked!'))
  .catch(err => console.log('It failed!', err));

get:

import { get } from 'idb-keyval';

// logs: "world"
get('hello').then(val => console.log(val));

If there is no 'hello' key, then val will be undefined .

keys:

import { keys } from 'idb-keyval';

// logs: ["hello", "foo"]
keys().then(keys => console.log(keys));

del:

import { del } from 'idb-keyval';

del('hello');

clear:

import { clear } from 'idb-keyval';

clear();

Custom stores:

By default, the methods above use an IndexedDB database named keyval-store and an object store named keyval . You can create your own store, and pass it as an additional parameter to any of the above methods:

import { Store, set } from 'idb-keyval';

const customStore = new Store('custom-db-name', 'custom-store-name');
set('foo', 'bar', customStore);

That's it!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值