Uncaught TypeError: Cannot read properties of undefined (reading 'type') from echarts

发布时间 2023-09-23 11:25:03作者: 凿壁偷光,集思广益

DON'T use ref or reactive to wrap the echarts instance. Use a common variable or shallowRef to avoid the deep watch for echarts instance.
不要使用 ref 或 reactive 来包装 echarts 实例。使用公共变量或 shallowRef 来避免对 echarts 实例的深度监视。

<template>
  <div ref='refMain' ></div>
</template>


  import { shallowRef, onMounted } from 'vue';

  const myChart = shallowRef();
  const refMain = ref(null);

  onMounted(() => {
    // 获取图表容器的 DOM 元素
    const chartDom = refMain.value;

    // 初始化
    myChart.value = echarts.init(chartDom);
  });