先上代码:
import dynamic from 'umi/dynamic';
import PageLoading from '@/components/pageLoading'; // 加载中动画
interface IType {
type: string,
height: string | number,
width: string | number,
coId: number
}
const ManagerChart : typeof React.Component = dynamic({
loader:() => import ( /* webpackChunkname : 'managerChart' */ '@/xxx/xxx/xxx.tsx')
loading:PageLoading
})
const ProjectWindow : typeof React.Component = dynamic({
loader : () => import (/* webpackChunkname : 'ProjectWindow'*/ '@/xxx/xxx/xxx.tsx')
loading:PageLoading
})
export default (props => IProps){
const { name , width , height , cold , type } = props;
const setComponent = (props) =>{
switch(name){
case: 'ManagerChart'
return <ManagerChart type={type} cold={cold} />;
case: 'ProjectWindow'
return <ProjectWindow />;
}
}
return (
{ setComponent() }
)
}
关键字:umi dynamic