From 7731e9ca4e02e058da0689d1209bcde5c8bf9d85 Mon Sep 17 00:00:00 2001 From: Georges KABBOUCHI Date: Sun, 2 Aug 2020 23:40:03 +0300 Subject: [PATCH] Update useTippy.ts --- src/composables/useTippy.ts | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/src/composables/useTippy.ts b/src/composables/useTippy.ts index 0802750..6d4879f 100644 --- a/src/composables/useTippy.ts +++ b/src/composables/useTippy.ts @@ -11,6 +11,7 @@ import { VNode, h, onUnmounted, + getCurrentInstance, } from 'vue' import { TippyOptions, TippyContent } from '../types' @@ -78,7 +79,7 @@ export function useTippy( instance.value.setContent(getContent(opts.content)) } - onMounted(() => { + const init = () => { if (!el) return let target = isRef(el) ? el.value : el @@ -86,14 +87,26 @@ export function useTippy( if (typeof target === 'function') target = target() target && (instance.value = tippy(target, getProps(opts))) - }) + } - onUnmounted(() => { - if (instance.value) { - instance.value.destroy() + const vm = getCurrentInstance() + + if (vm) { + if (vm.isMounted) { + init() + } else { + onMounted(init) } - container = null - }) + + onUnmounted(() => { + if (instance.value) { + instance.value.destroy() + } + container = null + }) + } else { + init() + } if (isRef(opts) || isReactive(opts)) { watch(opts, refresh, { immediate: false })