perf: performance optimization

This commit is contained in:
vben
2020-10-15 21:12:38 +08:00
parent 8f4d51a7cf
commit 70fba7ecac
15 changed files with 126 additions and 74 deletions

View File

@@ -14,6 +14,7 @@ export function useECharts(
) {
const chartInstanceRef = ref<Nullable<ECharts>>(null);
let resizeFn: Fn = resize;
let removeResizeFn: Fn = () => {};
const [debounceResize] = useDebounce(resize, 200);
resizeFn = debounceResize;
@@ -25,11 +26,12 @@ export function useECharts(
return;
}
chartInstanceRef.value = echarts.init(el, theme);
useEvent({
const { removeEvent } = useEvent({
el: window,
name: 'resize',
listener: resizeFn,
});
removeResizeFn = removeEvent;
const { widthRef, screenEnum } = useBreakpoint();
if (unref(widthRef) <= screenEnum.MD) {
useTimeout(() => {
@@ -37,6 +39,9 @@ export function useECharts(
}, 30);
}
}
tryOnUnmounted(() => {
removeResizeFn();
});
function setOptions(options: any, clear = true) {
nextTick(() => {