I was trying to find out how to use this plugin.
pinia-plugin-persistedstate
Using Option Stroe -> similar syntax to composition API.
And now i found out hope this will help someone.
For more go and read more docs at:
https://pinia.kimyang.cn
Main.ts
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
const app = createApp(App)
const pinia = createPinia()
pinia.use(piniaPluginPersistedstate)
app.use(pinia)
app.mount('#app')
sampleStore.ts
import { reactive } from 'vue'
import { defineStore } from 'pinia'
export const usePiniaStore = defineStore('piniaStore', ()=>{
const data = reactive({
count: 0,
examples: []
});
const addCount = () => {
data.count += 1;
}
const getCount = ()=> {
return data.count;
}
return { data, addCount, getCount}
},
{
persist: true,
});