echarts异步加载

echarts体积很大,在移动端使用异步加载是一种提高渲染速度的方法,结合webpack的做法如下:

require.ensure([], function(require){
    const echarts = require('assets/js/lib/echarts.min');
    if(echarts){
        _self.fInitEcharts(echarts);
        if(_self.dateList.length && _self.rateList.length){
            _self.fSetEcharts();
        }
    }
},'echarts');

//初始化echarts
fInitEcharts(echarts) {
    var id = this.user.isInvest == 0 ? 'container' : 'container_invest';
    var dom = document.getElementById(id);
    this.myChart = echarts.init(dom);
}

//设置echart选项
fSetEcharts(){
    if(this.myChart){
        const size = fGetChartFontSize();
        const option = ...;
        this.myChart.setOption(option, true);
    }
}

 

posted @ 2018-05-02 16:12  全玉  阅读(515)  评论(0编辑  收藏  举报