第一次提交

This commit is contained in:
2025-05-02 13:09:37 +08:00
commit ea5690fe88
39 changed files with 11346 additions and 0 deletions

12
src/ssr/ClientOnly.vue Normal file
View File

@ -0,0 +1,12 @@
<script setup>
import { useClientOnlyStore } from './clientOnlyStore.js'
const clientOnlyStore = useClientOnlyStore()
</script>
<template data-allow-mismatch>
<template v-if="clientOnlyStore.isClient" data-allow-mismatch>
<slot></slot>
</template><template v-else>
<slot name="ssr" data-allow-mismatch></slot>
</template>
</template>

25
src/ssr/ClientOnly1.vue Normal file
View File

@ -0,0 +1,25 @@
<script setup>
import { ref, onMounted, useSlots } from 'vue'
const isClient = ref(false)
const slots = useSlots()
onMounted(() => {
isClient.value = true
})
/*
USe:
<ClientOnly>
<template #ssr>
SSR Content
</template>
Real Content
</ClientOnly>
*/
</script>
<template data-allow-mismatch>
<template v-if="isClient" data-allow-mismatch><slot></slot></template>
<template v-else><slot name="ssr" data-allow-mismatch></slot></template>
</template>

View File

@ -0,0 +1,11 @@
import { ref } from 'vue'
import { defineStore } from 'pinia'
export const useClientOnlyStore = defineStore('ClientOnly', () => {
const isClient = ref(false)
function setClient() { isClient.value = true }
return {
isClient,
setClient
}
})

View File

@ -0,0 +1,9 @@
export function getInitialState(key) {
if (typeof window !== 'undefined' && window.__INITIAL_STATE__) {
if (window.__INITIAL_STATE__[key] !== undefined) {
let value = window.__INITIAL_STATE__[key]
delete window.__INITIAL_STATE__[key]
return value
}
}
}