pinia-persistent-store-plugin

1.0.3 • Public • Published

pinia-persistent-store-plugin

介绍

pinia的持久化存储插件,支持localStorage、sessionStorage、indexedDB,目前只在公司内部测试使用。

安装教程

npm install pinia-persistent-store-plugin -S

使用说明

    //main.ts
    import createStoragePlugin from "pinia-persistent-store-plugin"
	import { createPinia } from "pinia";
	const pinia = createPinia();
	pinia.use(
		createStoragePlugin({
			prefix: "prefix_",//本地存储时添加前缀
		})
	);
    //counter.ts
    const useCounterStore = defineStore("counter", {
    	persist: {
    		save_key: "user_user",
    		type: "DB",
    		paths: ["count"],
    	},
    	state: () => {
    		return { count: 0,list:[] };
    	},
    	actions: {},
    });
	const useCounterStore = defineStore("counter", {
		persist:true,
		state: () => {
			return { count: 0,list:[] };
		},
		actions: {},
	});

persist参数

    {
		save_key: "",//本地存储的key,createStoragePlugin传入前缀会拼接前缀
		type: "L",//本地存储的类型默认是L(localStorage),还有S(sessionStorage)、DB(indexedDB)
		paths: [],//state重某些需要本地存储的字段
		debounce: {//本地存储的防抖,频繁修改state会频繁触发本地存储,可以开启防抖,在某些时间内频发修改state不会触发本地存储
			open: false, //是否开启防抖
			wait: 1000,//防抖时间
		},
	};

Package Sidebar

Install

npm i pinia-persistent-store-plugin

Weekly Downloads

1

Version

1.0.3

License

ISC

Unpacked Size

12.4 kB

Total Files

10

Last publish

Collaborators

  • liqc