From 3a1ec7ac86d150791fe2472477be70fc456a78cd Mon Sep 17 00:00:00 2001 From: Lantz Date: Wed, 29 Mar 2023 14:58:18 +0800 Subject: [PATCH] =?UTF-8?q?fix(hooks):=20=E4=BF=AE=E6=94=B9=E5=9C=A8?= =?UTF-8?q?=E4=BD=BF=E7=94=A8useEcharts=E6=97=B6,=20getInstance=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E8=8E=B7=E5=8F=96=E5=88=B0=E6=9C=80=E6=96=B0=E7=9A=84?= =?UTF-8?q?echarts=E5=AE=9E=E4=BE=8B=E7=9A=84=E9=97=AE=E9=A2=98=20(#2650)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/web/useECharts.ts | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/hooks/web/useECharts.ts b/src/hooks/web/useECharts.ts index 6324e4a9..1c020036 100644 --- a/src/hooks/web/useECharts.ts +++ b/src/hooks/web/useECharts.ts @@ -60,23 +60,26 @@ export function useECharts( function setOptions(options: EChartsOption, clear = true) { cacheOptions.value = options; - if (unref(elRef)?.offsetHeight === 0) { - useTimeoutFn(() => { - setOptions(unref(getOptions)); - }, 30); - return; - } - nextTick(() => { - useTimeoutFn(() => { - if (!chartInstance) { - initCharts(getDarkMode.value as 'default'); + return new Promise((resolve) => { + if (unref(elRef)?.offsetHeight === 0) { + useTimeoutFn(() => { + setOptions(unref(getOptions)); + resolve(null); + }, 30); + } + nextTick(() => { + useTimeoutFn(() => { + if (!chartInstance) { + initCharts(getDarkMode.value as 'default'); - if (!chartInstance) return; - } - clear && chartInstance?.clear(); + if (!chartInstance) return; + } + clear && chartInstance?.clear(); - chartInstance?.setOption(unref(getOptions)); - }, 30); + chartInstance?.setOption(unref(getOptions)); + resolve(null); + }, 30); + }); }); }