11 changed files with 100 additions and 9 deletions
Binary file not shown.
@ -0,0 +1,17 @@ |
|||||
|
/* eslint-disable */ |
||||
|
// @ts-nocheck
|
||||
|
// Generated by unplugin-vue-components
|
||||
|
// Read more: https://github.com/vuejs/core/pull/3399
|
||||
|
// biome-ignore lint: disable
|
||||
|
export {} |
||||
|
|
||||
|
/* prettier-ignore */ |
||||
|
declare module 'vue' { |
||||
|
export interface GlobalComponents { |
||||
|
ClientOnly: typeof import('./src/components/ClientOnly.tsx')['default'] |
||||
|
CookieDemo: typeof import('./src/components/CookieDemo.vue')['default'] |
||||
|
DataFetch: typeof import('./src/components/DataFetch.vue')['default'] |
||||
|
HelloWorld: typeof import('./src/components/HelloWorld.vue')['default'] |
||||
|
SimpleTest: typeof import('./src/components/SimpleTest.vue')['default'] |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,43 @@ |
|||||
|
import { cloneVNode, createElementBlock, defineComponent, getCurrentInstance, h, InjectionKey, onMounted, provide, shallowRef, SlotsType, VNode } from "vue"; |
||||
|
|
||||
|
export const clientOnlySymbol: InjectionKey<boolean> = Symbol.for('nuxt:client-only') |
||||
|
|
||||
|
export default defineComponent({ |
||||
|
name: "ClientOnly", |
||||
|
inheritAttrs: false, |
||||
|
props: ['fallback', 'placeholder', 'placeholderTag', 'fallbackTag'], |
||||
|
...(import.meta.env.DEV && { |
||||
|
slots: Object as SlotsType<{ |
||||
|
default?: () => VNode[] |
||||
|
|
||||
|
/** |
||||
|
* Specify a content to be rendered on the server and displayed until `<ClientOnly>` is mounted in the browser. |
||||
|
*/ |
||||
|
fallback?: () => VNode[] |
||||
|
placeholder?: () => VNode[] |
||||
|
}>, |
||||
|
}), |
||||
|
setup(props, { slots, attrs }) { |
||||
|
const mounted = shallowRef(false) |
||||
|
onMounted(() => { mounted.value = true }) |
||||
|
const vm = getCurrentInstance() |
||||
|
if (vm) { |
||||
|
vm._nuxtClientOnly = true |
||||
|
} |
||||
|
provide(clientOnlySymbol, true) |
||||
|
return () => { |
||||
|
if (mounted.value) { |
||||
|
const vnodes = slots.default?.() |
||||
|
if (vnodes && vnodes.length === 1) { |
||||
|
return [cloneVNode(vnodes[0]!, attrs)] |
||||
|
} |
||||
|
return vnodes |
||||
|
} |
||||
|
const slot = slots.fallback || slots.placeholder |
||||
|
if (slot) { return h(slot) } |
||||
|
const fallbackStr = props.fallback || props.placeholder || '' |
||||
|
const fallbackTag = props.fallbackTag || props.placeholderTag || 'span' |
||||
|
return createElementBlock(fallbackTag, attrs, fallbackStr) |
||||
|
} |
||||
|
} |
||||
|
}) |
||||
@ -0,0 +1,10 @@ |
|||||
|
export { } |
||||
|
|
||||
|
declare module 'vue' { |
||||
|
export interface ComponentCustomProperties { |
||||
|
$ssrContext?: Record<string, any> |
||||
|
} |
||||
|
export interface ComponentInternalInstance { |
||||
|
_nuxtClientOnly?: boolean |
||||
|
} |
||||
|
} |
||||
@ -1,8 +1,13 @@ |
|||||
import { defineConfig } from 'vite' |
import { defineConfig } from 'vite' |
||||
import vue from '@vitejs/plugin-vue' |
import vue from '@vitejs/plugin-vue' |
||||
|
import Components from 'unplugin-vue-components/vite' |
||||
|
|
||||
// https://vite.dev/config/
|
// https://vite.dev/config/
|
||||
export default defineConfig({ |
export default defineConfig({ |
||||
base: './', |
base: './', |
||||
plugins: [vue()], |
plugins: [ |
||||
|
vue(), |
||||
|
Components({ dts: true, |
||||
|
extensions: ['vue', 'tsx'], }) |
||||
|
], |
||||
}) |
}) |
||||
|
|||||
Loading…
Reference in new issue