多维表格
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

34 lines
757 B

import { defineNuxtPlugin } from '#app'
import { useDark, watch } from '#imports'
import { useGlobalState } from '~/composables/useGlobalState'
/**
* Injects global state into nuxt app.
*
* @example
* ```js
* import { useNuxtApp } from '#app'
*
* const { $state } = useNuxtApp()
*
* console.log($state.lang.value) // 'en'
* ```
*/
export default defineNuxtPlugin((nuxtApp) => {
const storage = useGlobalState()
const darkMode = useDark()
/** set i18n locale to stored language */
nuxtApp.vueApp.i18n.locale.value = storage.lang.value
/** set current dark mode from storage */
watch(
storage.darkMode,
(newMode) => {
darkMode.value = newMode
},
{ immediate: true },
)
nuxtApp.provide('state', storage)
})