created () { this.getEchartData() }, getEchartData () { const param = { } this.$axios.get(url , param).then(res => { if (res.data && res.data.data) { this.echartData = res.data.data this.echartData.index = 0 this.selectEchart(0) } else { this.$Message.warning(res.data.return_msg) } }).catch((error) => { console.log(error) }) }, async selectEchart (val) { this.selectEchartData = this.echartData.voteData[val] let barChartRef = this.$echarts.init(this.$refs.barChartRef) //柱状图 let pieChartRef = this.$echarts.init(this.$refs.pieChartRef) // 饼状图 await this.renderBarChart() await this.renderPieChart() this.chartResize(barChartRef) this.chartResize(pieChartRef) console.log(this.selectEchartData) }, chartResize (chart) { // 重点部分 setTimeout(function () { chart.resize() window.addEventListener('resize', _ => { chart.resize() }) }, 200) },
标签:echart,barChartRef,res,chartResize,chart,适应,宽度,data,resize From: https://www.cnblogs.com/everseventh/p/17926728.html