From 8d19c31eda1fa2aa8b3329d273eda8312722a6c3 Mon Sep 17 00:00:00 2001 From: Maksim Fedotov Date: Tue, 9 Apr 2024 15:43:34 +0900 Subject: [PATCH] Add destroyDelay prop (#1085) * fix: use on-unmounted instead of on-before-unmount * feat: add destroyDelay prop --- src/chart.ts | 15 +++++++++++---- src/props.ts | 4 ++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/chart.ts b/src/chart.ts index 033c4356..f77b10ed 100644 --- a/src/chart.ts +++ b/src/chart.ts @@ -3,7 +3,7 @@ import { defineComponent, h, nextTick, - onBeforeUnmount, + onUnmounted, onMounted, ref, shallowRef, @@ -49,8 +49,15 @@ export const Chart = defineComponent({ const chart = toRaw(chartRef.value) if (chart) { - chart.destroy() - chartRef.value = null + if (props.destroyDelay > 0) { + setTimeout(() => { + chart.destroy() + chartRef.value = null + }, props.destroyDelay) + } else { + chart.destroy() + chartRef.value = null + } } } @@ -60,7 +67,7 @@ export const Chart = defineComponent({ onMounted(renderChart) - onBeforeUnmount(destroyChart) + onUnmounted(destroyChart) watch( [() => props.options, () => props.data], diff --git a/src/props.ts b/src/props.ts index a17254f7..1a2fec00 100644 --- a/src/props.ts +++ b/src/props.ts @@ -44,6 +44,10 @@ export const Props = { type: String as PropType, required: true }, + destroyDelay: { + type: Number, + default: 0 // No delay by default + }, ...CommonProps, ...A11yProps } as const