Skip to content

Commit 8d19c31

Browse files
authored
Add destroyDelay prop (#1085)
* fix: use on-unmounted instead of on-before-unmount * feat: add destroyDelay prop
1 parent f5ffcab commit 8d19c31

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/chart.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
defineComponent,
44
h,
55
nextTick,
6-
onBeforeUnmount,
6+
onUnmounted,
77
onMounted,
88
ref,
99
shallowRef,
@@ -49,8 +49,15 @@ export const Chart = defineComponent({
4949
const chart = toRaw(chartRef.value)
5050

5151
if (chart) {
52-
chart.destroy()
53-
chartRef.value = null
52+
if (props.destroyDelay > 0) {
53+
setTimeout(() => {
54+
chart.destroy()
55+
chartRef.value = null
56+
}, props.destroyDelay)
57+
} else {
58+
chart.destroy()
59+
chartRef.value = null
60+
}
5461
}
5562
}
5663

@@ -60,7 +67,7 @@ export const Chart = defineComponent({
6067

6168
onMounted(renderChart)
6269

63-
onBeforeUnmount(destroyChart)
70+
onUnmounted(destroyChart)
6471

6572
watch(
6673
[() => props.options, () => props.data],

src/props.ts

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ export const Props = {
4444
type: String as PropType<ChartType>,
4545
required: true
4646
},
47+
destroyDelay: {
48+
type: Number,
49+
default: 0 // No delay by default
50+
},
4751
...CommonProps,
4852
...A11yProps
4953
} as const

0 commit comments

Comments
 (0)