1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
| <template>
| <div
| :id="id"
| class="chartStyle"
| ></div>
| </template>
|
| <script>
| //页面引用
| import * as echarts from "echarts";
| export default {
| props: ["echartObj", "id"],
| data() {
| return {
| myChart: {},
| };
| },
| created() {
| this.$nextTick(() => {
| this.loadEchart();
| });
| },
|
| mounted() {
| let _this = this;
| window.onresize = function () {
| _this.myChart.resize();
| };
| },
| methods: {
| loadEchart() {
| // 动态绑定Id名这样就能解决传多个Echarts过来后只显示一个问题
| this.myChart = echarts.init(document.getElementById(this.id));
| console.log(this.echartObj);
| this.myChart.setOption({
| // 添加传入的对象中需要的属性
| ...this.echartObj,
| });
| },
| },
| };
| </script>
|
| <style scoped>
| .chartStyle {
| width: 100%;
| height: 100%;
| }
| </style>
|
|