安装 pinia-plugin-persistedstate
npm i pinia-plugin-persistedstate
main.ts
import App from './App.vue'
import { createPersistedState } from 'pinia-plugin-persistedstate'
import { createPinia } from 'pinia'
const pinia = createPinia()
pinia.use(createPersistedState())
const app = createApp(App)
app.use(pinia)
app.mount('#app')
store.ts
export const useRobotStore = defineStore('robot', () => {
...
}, {
persist: true
})