持久化存储

@ Persist
更多信息,请访问 NPM - pinia-plugin-persistedstate
状态的持久化存储通过第三方插件实现
本质上是使用了 localStorage
pinia-plugin-persistedstate
安装依赖
npm i pinia-plugin-persistedstate
main.js 中引入并使用
import { createPinia } from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'

const pinia = createPinia()
pinia.use(piniaPluginPersistedstate)
开启仓库的持久化选项
import { defineStore } from 'pinia'

export const useStore = defineStore('store', {
  state: () => ({
    someState: 'hello pinia',
  }),
  persist: true,
})