如何动态加载html文件到电子反应应用程序?

时间:2018-03-26 12:22:19

标签: javascript html reactjs electron

我正在使用反应和电子。我需要将一些外部html文件加载到我的一个组件中。在我将电子添加到我的应用程序之前工作正常但现在我有这个错误:

     Uncaught Error: Module parse failed: Unexpected token (1:0) You may
     need an appropriate loader to handle this file type. 
| <!DOCTYPE html> | <html> | <head>

            at Object../src/Partlists/9501.010400.html (.html$:23)
            at __webpack_require__ (bootstrap 1141b6c863a0f68d945d:678)
            at fn (bootstrap 1141b6c863a0f68d945d:88)
            at webpackContext (.html$:10)
            at BoxLabelContainer.getHTMLFile (BoxLabelContainer.js:266)
            at BoxLabelContainer.render (BoxLabelContainer.js:379)
            at finishClassComponent (react-dom.development.js:7873)
            at updateClassComponent (react-dom.development.js:7850)
            at beginWork (react-dom.development.js:8225)
            at performUnitOfWork (react-dom.development.js:10224)
            at workLoop (react-dom.development.js:10288)
            at HTMLUnknownElement.callCallback (react-dom.development.js:542)
            at Object.invokeGuardedCallbackDev (react-dom.development.js:581)
            at invokeGuardedCallback (react-dom.development.js:438)
            at renderRoot (react-dom.development.js:10366)
            at performWorkOnRoot (react-dom.development.js:11014)
            at performWork (react-dom.development.js:10967)
            at batchedUpdates (react-dom.development.js:11086)
            at batchedUpdates (react-dom.development.js:2330)
            at dispatchEvent (react-dom.development.js:3421)

我正在加载我的文件:

getHTMLFile(partNumber) {
    let html = require(`../Partlists/${partNumber}.html`);
    return {__html: `<div>${html}</div>`};
  }

<div dangerouslySetInnerHTML={this.getHTMLFile(this.state.selectedPartNumber)}></div>

我尝试了一切,但没有任何工作。我认为是因为构建应用程序的电子方式。有什么想法吗?

0 个答案:

没有答案