猿问

react Loadable import不同方式的问题

const Login = Loadable({ 

    loader: () => import('./components/Login'), 

    loading: () => <div>loading...</div> 

})

上面的很ok


下面的模块导出方式不一样

weather/index.js


import view from './views/weather.js'


export { view }

const Weather     = Loadable({ loader: () => {

    import { view as Weather } from './weather'

    这里的Weather我怎么返回给loader,(不修改weather/index的前提下)由于是异步的,直接返回肯定不行

}, loading:     () => <div>loading...</div> })


紫衣仙女
浏览 566回答 2
2回答

小怪兽爱吃肉

用下面的方式可以const Weather = Loadable({&nbsp;&nbsp; &nbsp; loader: () => import('./weather').then(({ view }) => view),&nbsp;&nbsp; &nbsp; loading: () => <div>loading...</div>&nbsp;});

红颜莎娜

const Weather = Loadable({&nbsp;&nbsp; &nbsp; loader: () => import('./views/weather.js').view,&nbsp;&nbsp; &nbsp; loading:&nbsp; () => <div>loading...</div>})
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答