3.0.0 • Published 4 months ago
pinia-plugin-store v3.0.0
pinia-plugin-store
pinia tools plugin
install
npm i pinia-plugin-store
API
property | type | description | default |
---|---|---|---|
stores | (string Ι StoreOptions)[] | pinia store keys(specify the store that needs to be persiste) | undefined |
storage | storage | persistent strategy | localStorage |
encrypt | (value: string) => string | persistent encryption | undefined |
decrypt | (value: string) => string | persistent decryption | undefined |
Example
theme.ts
import { defineStore } from 'pinia';
export const useThemeStore = defineStore('theme_store', {
state: () => {
return {
theme: 'dark',
};
},
actions: {
setTheme(theme: string) {
this.theme = theme;
},
},
});
Example 1
simple configuration
import { createPinia } from 'pinia';
import { storePlugin } from 'pinia-plugin-store';
const store = createPinia();
const plugin = storePlugin({
stores: ['theme_store'],
});
store.use(plugin);
export default store;
Example 2
specify a storage alone
import { createPinia } from 'pinia';
import { storePlugin } from 'pinia-plugin-store';
const store = createPinia();
const plugin = storePlugin({
stores: [{ name: 'theme_store', storage: sessionStorage }, 'user_store'],
storage: localStorage,
});
store.use(plugin);
export default store;
Example 3
encryption
import { createPinia } from 'pinia';
import { storePlugin } from 'pinia-plugin-store';
import Utf8 from 'crypto-js/enc-utf8';
import Base64 from 'crypto-js/enc-base64';
const store = createPinia();
function encrypt(value: string): string {
return Base64.stringify(Utf8.parse(value));
}
function decrypt(value: string): string {
return Base64.parse(value).toString(Utf8);
}
const plugin = storePlugin({
stores: [{ name: 'theme_store' }],
encrypt,
decrypt,
});
store.use(plugin);
export default store;
Example 4
disable encryption
import { createPinia } from 'pinia';
import { storePlugin } from 'pinia-plugin-store';
import Utf8 from 'crypto-js/enc-utf8';
import Base64 from 'crypto-js/enc-base64';
const store = createPinia();
function encrypt(value: string): string {
return Base64.stringify(Utf8.parse(value));
}
function decrypt(value: string): string {
return Base64.parse(value).toString(Utf8);
}
const plugin = storePlugin({
stores: [{ name: 'theme_store', ciphertext: false }],
storage: localStorage,
encrypt,
decrypt,
});
store.use(plugin);
export default store;
main.ts
import { createApp } from 'vue';
import store from './store';
import App from './App.vue';
const app = createApp(App);
app.use(store);
app.mount('#app');
3.0.0
4 months ago
2.3.0
6 months ago
2.3.2
6 months ago
2.3.1
6 months ago
2.3.3
6 months ago
2.2.9
8 months ago
2.2.7
10 months ago
2.2.8
9 months ago
2.2.3
12 months ago
2.2.2
12 months ago
2.2.5
11 months ago
2.2.4
11 months ago
2.2.6
11 months ago
2.2.1
1 year ago
2.2.0
2 years ago
2.1.37
2 years ago
2.1.19
2 years ago
2.1.21
2 years ago
2.1.20
2 years ago
2.1.36
2 years ago
2.1.34
2 years ago
2.1.35
2 years ago
2.1.32
2 years ago
2.1.33
2 years ago
2.1.30
2 years ago
2.1.31
2 years ago
2.1.18
2 years ago
2.1.17
2 years ago
2.1.16
3 years ago
2.1.14
3 years ago
2.1.15
3 years ago
2.1.12
3 years ago
2.1.13
3 years ago
2.1.10
3 years ago
2.1.11
3 years ago
2.1.2
3 years ago
2.1.1
3 years ago
2.1.4
3 years ago
2.1.3
3 years ago
2.1.6
3 years ago
2.1.5
3 years ago
2.1.8
3 years ago
2.1.7
3 years ago
2.1.9
3 years ago
2.0.7
3 years ago
2.0.6
3 years ago
2.1.0
3 years ago
2.0.5
3 years ago
2.0.4
3 years ago
2.0.3
3 years ago
2.0.2
3 years ago
2.0.1
3 years ago
2.0.0
3 years ago
1.0.5
3 years ago
1.0.4
3 years ago
1.0.3
3 years ago
1.0.2
3 years ago
1.0.1
3 years ago
1.0.0
3 years ago