我可以使用 npm run dev 在本地运行这个网络应用游戏。我怎样才能让它启动并运行我的反应应用程序。我不知道该寻求什么帮助,我有点绝望。
在React应用程序中,我导入了游戏的index.html文件,并尝试使用以下命令运行React应用程序:
import index from 'html-loader!./micropolisJS/index.html';
class App extends Component {
constructor(props) {
super(props);
}
render() {
return (
<iframe src={index}></iframe>
);
}
}
但这只是显示了html的内容,没有格式化,也没有任何功能。所有精灵都显示了 html 中某个位置打印到屏幕上的所有文本,但没有格式设置,也没有任何后面的功能。它只是说“嗯。那个地址看起来不对。 请检查网址是否正确,然后重试。”。我在这里真的很茫然,请发送一些帮助......
有时我也会收到此错误,但即使不进行任何更改,也不是每次都会出现:
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file.
See https://webpack.js.org/concepts#loaders
> <!DOCTYPE html>
您可以获取html文件,然后使用jsx渲染它
let test = <div> {index} </div>;
return (
<test/>
)
对于您提到的问题,我会考虑将 html 文件放在公共文件夹中,然后使用 Get 从 React 中获取它,然后使用上面显示的代码片段渲染响应
编辑: 您可以将要嵌入的 html 文件放在项目的公共 URL 上,然后将 iframe src 修改为:
<iframe src={process.env.PUBLIC_URL + '/index.html'}/>