fix: 🐛 修复echart图表在keep-alive缓存下切换其他页面缩放后再返回页面不能自适应问题

This commit is contained in:
hxr
2024-02-15 09:32:14 +08:00
parent cc6e2374dc
commit 972622d96d
5 changed files with 124 additions and 87 deletions

View File

@@ -87,14 +87,23 @@ const options = {
],
};
const chart = ref<any>("");
onMounted(() => {
const chart = echarts.init(
document.getElementById(props.id) as HTMLDivElement
chart.value = markRaw(
echarts.init(document.getElementById(props.id) as HTMLDivElement)
);
chart.setOption(options);
chart.value.setOption(options);
window.addEventListener("resize", () => {
chart.resize();
chart.value.resize();
});
});
onActivated(() => {
if (chart.value) {
chart.value.resize();
}
});
</script>