21 lines
546 B
TypeScript
21 lines
546 B
TypeScript
import { ref, watch } from 'vue'
|
|
|
|
export type ZiniaoVersion = 'new' | 'old'
|
|
|
|
const STORAGE_KEY = 'ziniao:version'
|
|
|
|
function loadZiniaoVersion(): ZiniaoVersion {
|
|
if (typeof window === 'undefined') return 'new'
|
|
return window.localStorage.getItem(STORAGE_KEY) === 'old' ? 'old' : 'new'
|
|
}
|
|
|
|
export function useZiniaoVersion() {
|
|
const ziniaoVersion = ref<ZiniaoVersion>(loadZiniaoVersion())
|
|
|
|
watch(ziniaoVersion, (value) => {
|
|
if (typeof window !== 'undefined') window.localStorage.setItem(STORAGE_KEY, value)
|
|
})
|
|
|
|
return ziniaoVersion
|
|
}
|