提交 8aa018d6 编写于 作者: View Design's avatar View Design

Update Chart.global.vue

上级 0bc38b77
...@@ -26,7 +26,7 @@ const props = defineProps({ ...@@ -26,7 +26,7 @@ const props = defineProps({
} }
}) })
let chart let chart
onMounted(() => { function init () {
chart = new Chart(document.getElementById('chart'), { chart = new Chart(document.getElementById('chart'), {
type: props.type, type: props.type,
data: { data: {
...@@ -42,10 +42,23 @@ onMounted(() => { ...@@ -42,10 +42,23 @@ onMounted(() => {
} }
} }
}) })
}
function destroy () {
if (chart) chart.destroy()
}
onMounted(() => {
init()
})
onBeforeUnmount(() => {
destroy()
}) })
watch(()=> colorMode.value, (value) => { watch(()=> colorMode.value, (value) => {
let color = '#e5e7eb' let color = '#e5e7eb'
if (value === 'dark') color = '#1f2937' if (value === 'dark') color = '#1f2937'
Chart.defaults.borderColor = color Chart.defaults.borderColor = color
if (chart) {
destroy()
init()
}
}, { immediate: true, deep: true }) }, { immediate: true, deep: true })
</script> </script>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册