Skip to content

Commit

Permalink
refactor: persist store to localstorage (#70)
Browse files Browse the repository at this point in the history
Add pinia plugin to persist store to localStorage
  • Loading branch information
raphodn authored Dec 26, 2023
1 parent 39ffc25 commit 9b44534
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"html5-qrcode": "^2.3.8",
"leaflet": "^1.9.4",
"pinia": "^2.1.7",
"pinia-plugin-persistedstate": "^3.2.1",
"universal-cookie": "^6.1.1",
"vue": "^3.3.9",
"vue-router": "^4.2.5",
Expand Down
3 changes: 3 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { createApp } from 'vue'
import { createPinia } from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import './assets/main.css'
import App from './App.vue'
import router from './router.js'
import { vuetify } from './plugins/vuetify.js'

const app = createApp(App)

const pinia = createPinia()
pinia.use(piniaPluginPersistedstate)

app.use(pinia)
app.use(router)
Expand Down
4 changes: 4 additions & 0 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@ export const useAppStore = defineStore('app', {
this.user.username = null
this.user.token = null
}
},
// pinia-plugin-persistedstate
persist: {
storage: localStorage
}
})
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,11 @@ picocolors@^1.0.0:
resolved "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz"
integrity sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==

pinia-plugin-persistedstate@^3.2.1:
version "3.2.1"
resolved "https://registry.yarnpkg.com/pinia-plugin-persistedstate/-/pinia-plugin-persistedstate-3.2.1.tgz#66780602aecd6c7b152dd7e3ddc249a1f7a13fe5"
integrity sha512-MK++8LRUsGF7r45PjBFES82ISnPzyO6IZx3CH5vyPseFLZCk1g2kgx6l/nW8pEBKxxd4do0P6bJw+mUSZIEZUQ==

pinia@^2.1.7:
version "2.1.7"
resolved "https://registry.yarnpkg.com/pinia/-/pinia-2.1.7.tgz#4cf5420d9324ca00b7b4984d3fbf693222115bbc"
Expand Down

0 comments on commit 9b44534

Please sign in to comment.