正常引用情况下 -------vue + vite 使用echarts 报错
import echarts from "echarts";
更改下面用法即可
import * as echarts from "echarts";
//这里一定得给高度
<div id="div1"></div>
<style>
#div1 {
width: 100%;
height: 500px;
}
</style>
<script>
import * as echarts from "echarts";
mounted() {
this.myEcharts();
}
methods: {
myEcharts() {
var myChart = echarts.init(document.getElementById("top1"));
var option = {
legend: {
data: ["邮件营销","联盟广告"],
},
yAxis: {
type: "value",
},
tooltip: {
trigger: "axis",
},
xAxis: {
type: "category",
data: [1 , 2]
},
series: [
{
name: "邮件营销",
type: "line",
data: [0, 5],
},
{
name: "联盟广告",
type: "line",
data: [3, 1],
},
],
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
}
}
</script>