vuejs怎么加载echarts

2021-09-28 16:30:13 IT技术网 互联网
浏览

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

本教程操作环境:windows7系统、vue2.9.6版,DELL G3电脑。

vuejs加载echarts

先npm安装vue-echarts

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教程》

以上就是vuejs怎么加载echarts的详细内容,更多请关注dnjidi.com其它相关文章!