• React 懒加载组件


     //组件第一次初始化的时候加载.

    import React, {PropTypes} from 'react';
    
    //import AppComposer from './views/App/AppComposer';
    //import LoginComposer from './views/Login/LoginComposer';
    //import HomeComposer from './views/Home/HomeComposer';
    //import WatchListComposer from './views/WatchList/WatchListComposer';
    //import SystemLogComposer from './views/SystemLog/SystemLogComposer';
    //import TeamManageComposer from './views/TeamManage/TeamManageComposer';
    //import {UserQueryPage} from './views/UserQuery/UserQueryComposer';
    //import ClosedCaseComposer from './views/ClosedCase/ClosedCaseComposer';
    //import AccountInfoComposer from './views/AccountInfo/AccountInfoComposer';
    
    
    function createLazyLoadComponent(doLoadComponent){
        return class newClassComponent extends React.Component{
    
            constructor(){
                super(...arguments);
                this.state = {
                    RealComponent : null
                };
            }
    
            componentDidMount(){
                //组件第一次初始化的时候加载.
                doLoadComponent((pageComponent)=>{
                    this.setState({
                        RealComponent:pageComponent
                    });
                });
            }
    
    
            render(){
                var {RealComponent} = this.state;
                var props = this.props;
                if (RealComponent){
                    return <RealComponent {...props} />
                }
                return <div>loading...</div>
            }
        }
    }
    
    
    export const LoginComposer = createLazyLoadComponent((onLoadCallback)=>{
         require(['./views/Login/LoginComposer'], onLoadCallback);
    });
    
    export const HomeComposer = createLazyLoadComponent((onLoadCallback)=>{
        require(['./views/Home/HomeComposer'], onLoadCallback);
    });
    
    export const WatchListComposer = createLazyLoadComponent((onLoadCallback)=>{
        require(['./views/WatchList/WatchListComposer'], onLoadCallback);
    });
    
    export const SystemLogComposer = createLazyLoadComponent((onLoadCallback)=>{
        require(['./views/SystemLog/SystemLogComposer'], onLoadCallback);
    });
    
    export const TeamManageComposer = createLazyLoadComponent((onLoadCallback)=>{
        require(['./views/TeamManage/TeamManageComposer'], onLoadCallback);
    });
    
    export const ClosedCaseComposer = createLazyLoadComponent((onLoadCallback)=>{
        require(['./views/ClosedCase/ClosedCaseComposer'], onLoadCallback);
    });
    
    export const AccountInfoComposer = createLazyLoadComponent((onLoadCallback)=>{
        require(['./views/AccountInfo/AccountInfoComposer'], onLoadCallback);
    });
    
    export const UserQueryPage = createLazyLoadComponent((onLoadCallback)=>{
        require(['./views/UserQuery/UserQueryComposer'], ({UserQueryPage})=>{
            onLoadCallback(UserQueryPage);
        });
    });
  • 相关阅读:
    数据类型及转换
    进制转换
    精通libGDX-RPG开发实战
    github上最好的开源MMORPG
    同步mysql数据到ElasticSearch的最佳实践
    在libGDX中使用Spine骨骼动画
    window下Kafka最佳实践
    linux 系统的负载与CPU、内存、硬盘、用户数监控脚本[marked]
    源码安装cmake(或者叫升级cmake)
    Rust-HayStack
  • 原文地址:https://www.cnblogs.com/lhp2012/p/6279782.html
Copyright © 2020-2023  润新知