无木
2021-06-04 fb6c76db535bd0c6305d03c0cff876a1f079100b
feat(echarts): add getInstance for useECharts

为useECharts添加getInstance以便绑定事件或执行更多自定义动作
1个文件已修改
26 ■■■■■ 已修改文件
src/hooks/web/useECharts.ts 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/hooks/web/useECharts.ts
@@ -23,17 +23,15 @@
  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);
@@ -100,9 +98,17 @@
    chartInstance = null;
  });
  function getInstance(): echarts.ECharts | null {
    if (!chartInstance) {
      initCharts(getDarkMode.value as 'default');
    }
    return chartInstance;
  }
  return {
    setOptions,
    resize,
    echarts,
    getInstance,
  };
}