Browse Source
fix(hooks): 修改在使用useEcharts时, getInstance无法获取到最新的echarts实例的问题 (#2650)
pull/2654/head
Lantz
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
18 additions and
15 deletions
-
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); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|