方法:1、使用“npm install echarts vue-echarts”语句安装vue-echarts;2、在“main.js”文件中引入vue-echarts模块;3、在需要的界面中,根据需要添加echarts代码即可。

本教程操作环境:windows7系统、vue2.9.6版,DELL G3电脑。
npm install echarts vue-echarts
main.js
import ECharts from 'vue-echarts'
import 'echarts/lib/chart/line'
Vue.component('chart', ECharts)HelloWorld.vue
立即学习“前端免费学习笔记(深入)”;
<template>
<p class="hello">
<chart ref="chart1" :options="orgOptions" :auto-resize="true"></chart>
</p>
</template>
<script>
export default {
name: 'HelloWorld',
data () {
return {
orgOptions: {},
}
},
mounted() {
this.orgOptions = {
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
type: 'value'
},
series: [{
data: [820, 932, 901, 934, 1290, 1330, 1320],
type: 'line',
smooth: true
}]
}
}
}
</script>到这里就结束了。试过打包了,没报错~
相关推荐:《vue.js教程》
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号