Skip to content

Commit

Permalink
Merge pull request #3986 from 1455668754/main
Browse files Browse the repository at this point in the history
fix: Echarts初始宽度监听修复
  • Loading branch information
vince292007 authored Jul 31, 2024
2 parents 77a0ad4 + f314826 commit d9bfe96
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/hooks/web/useECharts.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { EChartsOption } from 'echarts';
import type { Ref } from 'vue';
import { computed, nextTick, ref, unref, watch } from 'vue';
import { useTimeoutFn } from '@vben/hooks';
import { tryOnUnmounted, useDebounceFn } from '@vueuse/core';
import { unref, nextTick, watch, computed, ref } from 'vue';
import { useEventListener } from '@/hooks/event/useEventListener';
import { useBreakpoint } from '@/hooks/event/useBreakpoint';
import echarts from '@/utils/lib/echarts';
Expand Down Expand Up @@ -49,6 +49,10 @@ export function useECharts(
listener: resizeFn,
});
removeResizeFn = removeEvent;

const resizeObserver = new ResizeObserver(resizeFn);
resizeObserver.observe(el);

const { widthRef, screenEnum } = useBreakpoint();
if (unref(widthRef) <= screenEnum.MD || el.offsetHeight === 0) {
useTimeoutFn(() => {
Expand All @@ -64,7 +68,7 @@ export function useECharts(
useTimeoutFn(() => {
setOptions(unref(getOptions));
resolve(null);
}, 30);
}, 50);
}
nextTick(() => {
useTimeoutFn(() => {
Expand Down

0 comments on commit d9bfe96

Please sign in to comment.