在做项目的时候,图表画出来了,但是点击legend就会报错,记录一下解决方法
错误写法:
<template>
<div class="echarts_container" ref="echarts_container">
</div>
</template>
<script setup lang='ts'>
import { ref, onMounted, onUnmounted } from "vue";
const echarts_container = ref();
//let myChart = ref(); //错误地方就是这里,不能用ref代理
let machrt = null; //正确写法
let option = {
....
}
onMounted(() => {
myChart = echarts.init(echarts_container.value);
option && myChart.setOption(option);
});
onUnmounted(() => {
myChart.destroy();
});
</script>