fix: avoid rendering content in SSR

This commit is contained in:
Julian Hundeloh
2021-12-16 14:59:49 +01:00
committed by GitHub
parent dcff577724
commit 2bfa01988c
+5 -2
View File
@@ -68,6 +68,7 @@ const TippyComponent = defineComponent({
setup(props, { slots }) {
const elem = ref<Element>()
const contentElem = ref<Element>()
const mounted = ref(false)
let options = { ...props } as TippyOptions;
@@ -91,17 +92,19 @@ const TippyComponent = defineComponent({
const tippy = useTippy(target, options)
onMounted(() => {
mounted.value = true
if (slots.content)
tippy.setContent(() => contentElem.value)
})
return { elem, contentElem, ...tippy }
return { elem, contentElem, mounted, ...tippy }
},
render() {
let slot = this.$slots.default ? this.$slots.default(this) : []
return h(this.tag, { ref: 'elem', 'data-v-tippy': '' }, this.$slots.content ? [
slot,
h(this.contentTag, { ref: 'contentElem', class: this.contentClass }, this.$slots.content(this))
this.mounted ? h(this.contentTag, { ref: 'contentElem', class: this.contentClass }, this.$slots.content(this)) : undefined,
] : slot)
},
})