From 8aa018d6128740f08bdd4af9dfdfa6206ffdd7ac Mon Sep 17 00:00:00 2001 From: Aresn Date: Wed, 5 Jun 2024 15:22:09 +0800 Subject: [PATCH] Update Chart.global.vue --- components/prose/Chart.global.vue | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/components/prose/Chart.global.vue b/components/prose/Chart.global.vue index 2b815eb..e9bb555 100644 --- a/components/prose/Chart.global.vue +++ b/components/prose/Chart.global.vue @@ -26,7 +26,7 @@ const props = defineProps({ } }) let chart -onMounted(() => { +function init () { chart = new Chart(document.getElementById('chart'), { type: props.type, data: { @@ -42,10 +42,23 @@ onMounted(() => { } } }) +} +function destroy () { + if (chart) chart.destroy() +} +onMounted(() => { + init() +}) +onBeforeUnmount(() => { + destroy() }) watch(()=> colorMode.value, (value) => { let color = '#e5e7eb' if (value === 'dark') color = '#1f2937' Chart.defaults.borderColor = color + if (chart) { + destroy() + init() + } }, { immediate: true, deep: true }) -- GitLab