2021-10-20

升级echarts5.2.1后突然resize 不管用,经过一番折腾,又OK了,这感觉倍棒

主要是碰到了这个错误 resize should not be called during main process
在这里插入图片描述

原因还没理解透彻,急于完成工作任务,先记下来解决方法,后面再来回顾,
我猜又很多人也跟我一样在这浪费了不少时间

// An highlighted block
<!--
 * @Author: vince
 * @Date: 2020-07-24 10:19:05
 * @LastEditors: vince 273187189@qq.com
 * @LastEditTime: 2021-10-20 15:49:01
 * @Description: 
-->
<template>
	<div class="fit" ref="charts"></div>
</template>

<script>
import { shallowRef, onMounted, watch, ref, onBeforeUnmount } from "vue";
import * as echarts from "echarts";
require("echarts-liquidfill");
export default {
	props: {
		option: {
			type: Object,
		},
	},
	setup(props, context) {
		const timeOut = ref(null);
		const charts = ref(null);
		const myChart = shallowRef(null);

		onMounted(() => {
			myChart.value = echarts.init(charts.value, "chalk");
			myChart.value.setOption(props.option, { notMerge: true });
			const resizeObserver = new ResizeObserver((entries) => {
				if (timeOut.value != null) {
					clearTimeout(timeOut.value);
				}
				timeOut.value = setTimeout(() => {
					myChart.value.resize({
						width: null,
						height: null,
					});
				}, 350);
			});
			resizeObserver.observe(charts.value.parentNode);
		});

		onBeforeUnmount(() => {
			myChart.value.dispose();
		});

		watch(
			() => props.option,
			(newVal) => {
				myChart.value.setOption(newVal, { notMerge: true });
			},
			{ deep: true }
		);

		return {
			charts,
			myChart,
		};
	},
};
</script>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值