2023-09-05 08:42:16 +00:00
|
|
|
import destr from 'destr'
|
2023-04-11 11:58:43 +00:00
|
|
|
import { defineNuxtPlugin, useNuxtApp } from '#app/nuxt'
|
2023-03-08 12:17:22 +00:00
|
|
|
|
2023-04-11 11:58:43 +00:00
|
|
|
export default defineNuxtPlugin({
|
|
|
|
name: 'nuxt:restore-state',
|
|
|
|
hooks: {
|
|
|
|
'app:mounted' () {
|
|
|
|
const nuxtApp = useNuxtApp()
|
|
|
|
try {
|
|
|
|
const state = sessionStorage.getItem('nuxt:reload:state')
|
|
|
|
if (state) {
|
|
|
|
sessionStorage.removeItem('nuxt:reload:state')
|
2023-09-05 08:42:16 +00:00
|
|
|
Object.assign(nuxtApp.payload.state, destr<Record<string, any>>(state)?.state)
|
2023-04-11 11:58:43 +00:00
|
|
|
}
|
|
|
|
} catch {}
|
|
|
|
}
|
|
|
|
}
|
2023-03-08 12:17:22 +00:00
|
|
|
})
|