封装思路:
1.定义个组件,在里面对折线图的代码进行封装
2.将想要动态传入的参数进行抽取
3.在其他页面传入相关的参数,直接展示出图标
具体代码:
1.封装的组件的页面代码
<template>
<div class="index_card" :style="{ height: chartHeight, width: chartWidth }">
<Echart :options="options" :id="chartId" class="echarts_bottom"></Echart>
</div>
</template>
<script>
import * as echarts from 'echarts'
export default {
props: {
firstData: {
type: Array,
default: []
},
secondData: {
type: Array,
default: []
},
xAxisData: {
type: Array,
default: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
},
legendData: {
type: Array,
default: []
},
chartHeight: {
type: String,
default: '300px' // 默认高度为 400px
},
chartWidth: {
type: String,
default: '100%' // 默认高度为 400px
},
name: {
type: String,
default: ''
},
xAxisTickShow: {
type: Boolean,
default: false
},
yAxisTickShow: {
type: Boolean,
default: false
},
ySplitLineShow: {
type: Boolean,