This commit is contained in:
Mrhongxing committed 2026-11-04 14:22:20 +08:00
commit 4aaaf23d2f
2411 files changed
+1248679

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
import { useCookie, useRuntimeConfig } from "#app";
function cookies(options) {
return {
getItem: (key) => useCookie(
key,
{
...options ?? useRuntimeConfig().public.piniaPluginPersistedstate.cookieOptions ?? {},
decode: options?.decode ?? decodeURIComponent,
readonly: true
}
).value,
setItem: (key, value) => useCookie(
key,
{
...options ?? useRuntimeConfig().public.piniaPluginPersistedstate.cookieOptions ?? {},
encode: options?.encode ?? encodeURIComponent
}
).value = value
};
}
function localStorage() {
return {
getItem: (key) => import.meta.client ? window.localStorage.getItem(key) : null,
setItem: (key, value) => import.meta.client ? window.localStorage.setItem(key, value) : null
};
}
function sessionStorage() {
return {
getItem: (key) => import.meta.client ? window.sessionStorage.getItem(key) : null,
setItem: (key, value) => import.meta.client ? window.sessionStorage.setItem(key, value) : null
};
}
export const storages = {
cookies,
localStorage,
sessionStorage
};