npm 安装echarts
npm install echarts -S
安装好之后在<script>
引入echarts
import * as echarts from 'echarts'
在template标签中引用
<div id="main" style="width: 100%; height: 400px;">/div>
在export default
中创建mounted
页面元素渲染之后再触发
完整Vue代码
<template>
<div id="main" style="width: 100%; height: 400px;">
</div>
</template>
<script>
import * as echarts from 'echarts'
export default {
name: "StudyIndex",
data() {
return {}
},
mounted() {
var chartDom = document.getElementById('main');
var myChart = echarts.init(chartDom);
var option;
option = {
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
type: 'value'
},
series: [
{
data: [150, 230, 224, 218, 135, 147, 260],
type: 'line'
}
]
};
myChart.setOption(option);
},
};
</script>
效果图
标签:Vue,option,data,export,整合,var,type,echarts From: https://blog.csdn.net/2301_80488214/article/details/140101791