Vue如何使用ECharts
- 安装echarts依赖
npm install echarts --save
- 新建两个vue文件
- 在子组件中先引用echarts
<sript>
import * as echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
<script>
或者可以直接复制我下面的代码(只要安装了echarts包之后,可以直接复制使用):
<template>
<div :class="className" :style="{height:height,width:width}" />
</template>
<script>
import * as echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
export default {
props: {
className: {
type: String,
default: 'chart'
},
width: {
type: String,
default: '100%'
},
height: {
type: String,
default: '300px'
}
},
data() {
return {
chart: null
}
},
mounted()<