【异常】报错:TypeError: Cannot read properties of undefined (reading ‘init‘)

曾经终败给现在 2024-02-17 11:35 134阅读 0赞

一、报错内容

在vue当中引用echarts,控制台报错: “TypeError: Cannot read properties of undefined (reading ‘init‘)
在这里插入图片描述

二、 报错说明

因为引用了echarts里面的init方法显示没有定义

  1. import {
  2. userStatistics } from "@/api/chart";
  3. import echarts from "echarts";
  4. require("echarts/theme/macarons"); // echarts theme
  5. import resize from "../mixins/resize";

三、报错解决

import echarts from 'echarts' 的引入方式改为:import * as echarts from 'echarts'

  1. import {
  2. userStatistics } from "@/api/chart";
  3. import * as echarts from 'echarts';
  4. require("echarts/theme/macarons"); // echarts theme
  5. import resize from "../mixins/resize";

控制台不再报错

发表评论

表情:
评论列表 (有 0 条评论,134人围观)

还没有评论,来说两句吧...

相关阅读