From 874734b638a1280af7152b1c2da39edd50c0e472 Mon Sep 17 00:00:00 2001 From: doutatsu Date: Thu, 29 Feb 2024 15:04:21 +0900 Subject: [PATCH 1/2] fix: use on-unmounted instead of on-before-unmount --- src/chart.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/chart.ts b/src/chart.ts index 033c4356..832b51ff 100644 --- a/src/chart.ts +++ b/src/chart.ts @@ -3,7 +3,7 @@ import { defineComponent, h, nextTick, - onBeforeUnmount, + onUnmounted, onMounted, ref, shallowRef, @@ -60,7 +60,7 @@ export const Chart = defineComponent({ onMounted(renderChart) - onBeforeUnmount(destroyChart) + onUnmounted(destroyChart) watch( [() => props.options, () => props.data], From 3e5ed0891ed939ade86ed1d376e0bb71110f1725 Mon Sep 17 00:00:00 2001 From: doutatsu Date: Mon, 4 Mar 2024 11:59:32 +0900 Subject: [PATCH 2/2] feat: add destroyDelay prop --- src/chart.ts | 11 +++++++++-- src/props.ts | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/chart.ts b/src/chart.ts index 832b51ff..f77b10ed 100644 --- a/src/chart.ts +++ b/src/chart.ts @@ -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 + } } } 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