From fb6c76db535bd0c6305d03c0cff876a1f079100b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=A0=E6=9C=A8?= Date: Fri, 4 Jun 2021 17:22:06 +0800 Subject: [PATCH] feat(echarts): add getInstance for useECharts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为useECharts添加getInstance以便绑定事件或执行更多自定义动作 --- src/hooks/web/useECharts.ts | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/hooks/web/useECharts.ts b/src/hooks/web/useECharts.ts index d81591f18..60335d04f 100644 --- a/src/hooks/web/useECharts.ts +++ b/src/hooks/web/useECharts.ts @@ -23,17 +23,15 @@ export function useECharts( resizeFn = useDebounceFn(resize, 200); - const getOptions = computed( - (): EChartsOption => { - if (getDarkMode.value !== 'dark') { - return cacheOptions.value; - } - return { - backgroundColor: 'transparent', - ...cacheOptions.value, - }; + const getOptions = computed((): EChartsOption => { + if (getDarkMode.value !== 'dark') { + return cacheOptions.value; } - ); + return { + backgroundColor: 'transparent', + ...cacheOptions.value, + }; + }); function initCharts(t = theme) { const el = unref(elRef); @@ -100,9 +98,17 @@ export function useECharts( chartInstance = null; }); + function getInstance(): echarts.ECharts | null { + if (!chartInstance) { + initCharts(getDarkMode.value as 'default'); + } + return chartInstance; + } + return { setOptions, resize, echarts, + getInstance, }; }