解决Echarts封装成组件时只有最后一个才会缩放的问题

参考了此文,并且强烈建议去看http://blog.csdn.net/crper/article/details/76091755

一般网上的方法都是

 mounted() {
        this.drawChart();
        window.onresize=()=>{
            console.log(this.id)
            this.chart.resize();
        }
      }

这么做,在多个组件的情况下,只有最后一个组件会进行缩放。

其实只需要这么做就可以了:

mounted() {
        this.drawChart();
        window.addEventListener('resize', ()=>{
            setTimeout(() => {this.chart.resize();},100)
        });
      }

添加了延迟函数是为了增强一下性能

  

原文地址:https://www.cnblogs.com/blueroses/p/8491473.html