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); } }