webpack使用return import().then()这个函数,如果我想一起引jquery和echarts,如何改?

import React from 'react';

/**
 * 描述:Echarts 千层饼
 */

class Foundation extends React.Component {

    constructor() {
        super();
    }

    _init() {
        // 参数设置
        var doc = document.getElementsByClassName('cs001')[0]
        //var optionECharts = this.props.defaultProps;
        return import(/* webpackChunkName: "echarts" */ 'echarts').then(echarts => {
            // 基于准备好的dom,初始化echarts实例
            var myChart = echarts.init(doc);
            // 指定图表的配置项和数据
            var app = {};

            app.title = '极坐标系下的堆叠柱状图';

            var option = {
                angleAxis: {
                },
                radiusAxis: {
                    type: 'category',
                    data: ['周一', '周二', '周三', '周四'],
                    z: 10
                },
                polar: {
                },
                series: [{
                    type: 'bar',
                    data: [1, 2, 3, 4],
                    coordinateSystem: 'polar',
                    name: 'A',
                    stack: 'a'
                }, {
                    type: 'bar',
                    data: [2, 4, 6, 8],
                    coordinateSystem: 'polar',
                    name: 'B',
                    stack: 'a'
                }, {
                    type: 'bar',
                    data: [1, 2, 3, 4],
                    coordinateSystem: 'polar',
                    name: 'C',
                    stack: 'a'
                }],
                legend: {
                    show: true,
                    data: ['A', 'B', 'C']
                }
            };

            // 使用刚指定的配置项和数据显示图表。

            if (option && typeof option === "object") {
                myChart.setOption(option, true);
            }


        }).catch(error => 'An error occurred while loading the component');
    }


    componentDidMount() {

        this._init()
    }



    render() {
        return (
            <div className={'cs001'} style={{width: 800, height: 800}}>

            </div>


        )
    }
}


export default Foundation;
阅读 4.5k
1 个回答
Promise.all([import('echarts'), import('jquery')]).then(libs => {
  var echarts = libs[0];
  var $ = libs[1];
});
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题