npm install localforage
yarn add localforage
import React from 'react';
import { Button } from 'antd';
import localforage from 'localforage';
// localforage 操作数据增删改查均为异步操作
const STORE = localforage.createInstance({
driver: localforage.INDEXEDDB, // 使用indexDB
name: 'vite-test', // 数据库名称
version: 2.0, // 版本
});
export default function study11() {
const addStore = () => {
// set
STORE.setItem('cvt', { name: 'haha', age: 30, sex: '男' });
// get
// STORE.getItem('cvt').then(res => {});
};
return (
<div>
<Button type="primary" onClick={addStore}>
新增数据
</Button>
</div>
);
}