naive-ui/demo/util-composables.js

43 lines
872 B
JavaScript
Raw Normal View History

2020-09-27 22:27:25 +08:00
import {
computed,
ref,
toRef,
inject
} from 'vue'
export function useDisplayMode () {
const devModeRef = ref(
localStorage.getItem('mode') ? localStorage.getItem('mode') : 'debug'
)
return computed({
get () {
return devModeRef.value
},
set (value) {
devModeRef.value = value
localStorage.setItem('mode', value)
}
})
}
export const displayModeRef = useDisplayMode()
export function useSiteTheme () {
return toRef(inject('SiteProvider'), 'theme')
}
export function useSiteLang () {
return toRef(inject('SiteProvider'), 'lang')
}
2020-10-07 20:45:51 +08:00
export const i18n = function (data) {
const configProvider = inject('NConfigProvider', null)
return {
2020-10-08 04:14:14 +08:00
locale: toRef(configProvider, 'inheritedLanguage'),
2020-10-07 20:45:51 +08:00
t (key) {
const { inheritedLanguage } = configProvider
return data[inheritedLanguage][key]
}
}
}