使用 react 16之后的特性 React.lazy 参考链接
废话不说直接上代码
- 引入
@loadable/component插件,官网推荐使用 - 动态 import 需要的组件
import React from 'react';
import loadable from '@loadable/component';
const OtherComponent = loadable(() => {
if(true){
return import('./A.jsx')
}
})
const IndexView = (props) => {
return (
<div>
<OtherComponent>123123</OtherComponent>
</div>
);
};
export default IndexView;