1.安装echarts
npm install echarts --save
2.引入echarts
(1)全局引入,挂到Vue的原型链上
在main.js中加入以下代码
import echarts from 'echarts' //引入echarts
Vue.prototype.$echarts = echarts //挂载在原型,组件内使用直接this.$echarts调用
(2)按需引入(体积较小,推荐使用)
//在组件引入基本模板
let echarts = require("echarts/lib/echarts");
//在组件引入柱状图组件
require("echarts/lib/chart/bar");
3.按需引入示例
<template>
<div id="container" style="width:300px;height:300px;"></div>
</template>
<script>
let echarts = require("echarts/lib/echarts");
require("echarts/lib/chart/bar");
export default {
mounted() {
this.drawLine();
},
methods: {
drawLine() {
let myChart = echarts.init(document.getElementById("container"));
let option = {