【发布时间】:2018-11-07 19:09:18
【问题描述】:
我正在使用fetch-mock 来模拟使用 fetch 的实际组件。 fetch-mock 不支持 ie11 并且希望仅在支持浏览器的情况下导入示例组件。我怎样才能做到这一点?
- ABCExampleComponent 使用
fetch-mock模拟ABCComponent 中使用的fetch。 - LoadComponent 仅在浏览器受支持时才应呈现 ABCExampleComponent。
加载组件
const isIE11 = !!window.MSInputMethodContext && !!document.documentMode;
if(!isIE11){
import ABCExampleComponent from './ABCExampleComponent';
}
//or
const ABCExampleComponent = !isIE11 ? import('./ABCExampleComponent') : null;
const LoadComponent = ( ) => {
<ABCExampleComponent />
}
感谢您的建议。
【问题讨论】:
-
你使用的是什么版本的 React?可以选择 v16.6 吗?
标签: reactjs webpack fetch dynamic-import fetch-mock