提交 fb6c76db 作者: 无木

feat(echarts): add getInstance for useECharts

为useECharts添加getInstance以便绑定事件或执行更多自定义动作
上级 46899aa3
...@@ -23,8 +23,7 @@ export function useECharts( ...@@ -23,8 +23,7 @@ export function useECharts(
resizeFn = useDebounceFn(resize, 200); resizeFn = useDebounceFn(resize, 200);
const getOptions = computed( const getOptions = computed((): EChartsOption => {
(): EChartsOption => {
if (getDarkMode.value !== 'dark') { if (getDarkMode.value !== 'dark') {
return cacheOptions.value; return cacheOptions.value;
} }
...@@ -32,8 +31,7 @@ export function useECharts( ...@@ -32,8 +31,7 @@ export function useECharts(
backgroundColor: 'transparent', backgroundColor: 'transparent',
...cacheOptions.value, ...cacheOptions.value,
}; };
} });
);
function initCharts(t = theme) { function initCharts(t = theme) {
const el = unref(elRef); const el = unref(elRef);
...@@ -100,9 +98,17 @@ export function useECharts( ...@@ -100,9 +98,17 @@ export function useECharts(
chartInstance = null; chartInstance = null;
}); });
function getInstance(): echarts.ECharts | null {
if (!chartInstance) {
initCharts(getDarkMode.value as 'default');
}
return chartInstance;
}
return { return {
setOptions, setOptions,
resize, resize,
echarts, echarts,
getInstance,
}; };
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论