Commit 3a1ec7ac86d150791fe2472477be70fc456a78cd
Committed by
GitHub
1 parent
4c63b1ab
fix(hooks): 修改在使用useEcharts时, getInstance无法获取到最新的echarts实例的问题 (#2650)
Showing
1 changed file
with
18 additions
and
15 deletions
src/hooks/web/useECharts.ts
@@ -60,23 +60,26 @@ export function useECharts( | @@ -60,23 +60,26 @@ export function useECharts( | ||
60 | 60 | ||
61 | function setOptions(options: EChartsOption, clear = true) { | 61 | function setOptions(options: EChartsOption, clear = true) { |
62 | cacheOptions.value = options; | 62 | cacheOptions.value = options; |
63 | - if (unref(elRef)?.offsetHeight === 0) { | ||
64 | - useTimeoutFn(() => { | ||
65 | - setOptions(unref(getOptions)); | ||
66 | - }, 30); | ||
67 | - return; | ||
68 | - } | ||
69 | - nextTick(() => { | ||
70 | - useTimeoutFn(() => { | ||
71 | - if (!chartInstance) { | ||
72 | - initCharts(getDarkMode.value as 'default'); | 63 | + return new Promise((resolve) => { |
64 | + if (unref(elRef)?.offsetHeight === 0) { | ||
65 | + useTimeoutFn(() => { | ||
66 | + setOptions(unref(getOptions)); | ||
67 | + resolve(null); | ||
68 | + }, 30); | ||
69 | + } | ||
70 | + nextTick(() => { | ||
71 | + useTimeoutFn(() => { | ||
72 | + if (!chartInstance) { | ||
73 | + initCharts(getDarkMode.value as 'default'); | ||
73 | 74 | ||
74 | - if (!chartInstance) return; | ||
75 | - } | ||
76 | - clear && chartInstance?.clear(); | 75 | + if (!chartInstance) return; |
76 | + } | ||
77 | + clear && chartInstance?.clear(); | ||
77 | 78 | ||
78 | - chartInstance?.setOption(unref(getOptions)); | ||
79 | - }, 30); | 79 | + chartInstance?.setOption(unref(getOptions)); |
80 | + resolve(null); | ||
81 | + }, 30); | ||
82 | + }); | ||
80 | }); | 83 | }); |
81 | } | 84 | } |
82 | 85 |