Skip to content

Commit 671d56e

Browse files
committed
update: 修改 echarts 传值方式
1 parent 0eb64b1 commit 671d56e

2 files changed

Lines changed: 12 additions & 28 deletions

File tree

‎components/mpvue-echarts/src/echarts.vue‎

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@ import WxCanvas from './wx-canvas';
77
88
export default {
99
props: {
10-
// onInit: {
11-
// required: true,
12-
// type: Function,
13-
// default: null,
14-
// },
1510
canvasId: {
1611
type: String,
1712
default: 'ec-canvas'
@@ -39,16 +34,15 @@ export default {
3934
if (!this.lazyLoad) this.init();
4035
},
4136
// #endif
42-
methods: {
37+
methods: {
38+
setChart(chart){
39+
this.chart = chart
40+
},
4341
init() {
44-
// if (!this.onInit) {
45-
// console.warn('请传入 onInit 函数进行初始化');
46-
// return;
47-
// }
4842
const { canvasId } = this;
4943
this.ctx = wx.createCanvasContext(canvasId, this);
5044
51-
const canvas = new WxCanvas(this.ctx, canvasId);
45+
this.canvas = new WxCanvas(this.ctx, canvasId);
5246
5347
const query = wx.createSelectorQuery().in(this);
5448
query
@@ -59,15 +53,9 @@ export default {
5953
return;
6054
}
6155
this.$emit('onInit', {
62-
canvas,
6356
width: res.width,
64-
height: res.height,
65-
fire: chart => {
66-
console.log(chart);
67-
this.chart = chart;
68-
}
57+
height: res.height
6958
});
70-
// this.chart = this.onInit(canvas, res.width, res.height);
7159
})
7260
.exec();
7361
},

‎pages/template/echarts/echarts.vue‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@
9393
export default {
9494
data() {
9595
return {
96-
// echarts: echarts,
9796
updateStatus: false
9897
}
9998
},
@@ -119,9 +118,9 @@
119118
this.$refs.pieChart.init();
120119
this.updateStatus = true;
121120
},
122-
// pieInit(canvas, width, height) {
123121
pieInit(e) {
124-
let {canvas, width, height,fire} = e ;
122+
let { width, height} = e ;
123+
let canvas = this.$refs.pieChart.canvas
125124
echarts.setCanvasCreator(() => canvas);
126125
let pieChart = echarts.init(canvas, null, {
127126
width: width,
@@ -130,22 +129,19 @@
130129
canvas.setChart(pieChart)
131130
132131
pieChart.setOption(pieOption)
133-
fire(pieChart)
134-
// return pieChart
132+
this.$refs.pieChart.setChart(pieChart)
135133
},
136-
// lineInit(canvas, width, height) {
137134
lineInit(e) {
138-
let {canvas, width, height,fire} = e ;
135+
let {width, height} = e ;
136+
let canvas = this.$refs.lineChart.canvas
139137
echarts.setCanvasCreator(() => canvas);
140138
let lineChart = echarts.init(canvas, null, {
141139
width: width,
142140
height: height
143141
})
144142
canvas.setChart(lineChart)
145-
146143
lineChart.setOption(lineOption)
147-
fire(lineChart)
148-
// return lineChart
144+
this.$refs.lineChart.setChart(lineChart)
149145
}
150146
},
151147
components: {

0 commit comments

Comments
 (0)