Skip to content

Commit

Permalink
feat(echarts): add getInstance for useECharts
Browse files Browse the repository at this point in the history
为useECharts添加getInstance以便绑定事件或执行更多自定义动作
  • Loading branch information
mynetfan committed Jun 4, 2021
1 parent 46899aa commit fb6c76d
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/hooks/web/useECharts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
};
}

0 comments on commit fb6c76d

Please sign in to comment.