Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将外部html文件导入React应用程序?_Javascript_Reactjs - Fatal编程技术网

Javascript 如何将外部html文件导入React应用程序?

Javascript 如何将外部html文件导入React应用程序?,javascript,reactjs,Javascript,Reactjs,我有一个项目正在开发中。我需要使用外部登录页作为主页。因此,我需要导入landings index.html,但它有自己的带有css和js的文件夹(主要是Jquery代码) 我想将它作为导入到我的项目中,但我的应用程序似乎没有加载htmls 导入使用自己的jquery代码进行响应的html文件的最佳方法是什么?这有点棘手,可能还有其他方法(也许更好)来实现相同的结果。此外,我将考虑将多个库加载到现有的反应应用程序中的性能影响。p> 有了这个谦逊的免责声明,一种方法是使用标记将jQuery直接包含

我有一个项目正在开发中。我需要使用外部登录页作为主页。因此,我需要导入landings index.html,但它有自己的带有css和js的文件夹(主要是Jquery代码)

我想将它作为
导入到我的项目中,但我的应用程序似乎没有加载htmls


导入使用自己的jquery代码进行响应的html文件的最佳方法是什么?

这有点棘手,可能还有其他方法(也许更好)来实现相同的结果。此外,我将考虑将多个库加载到现有的反应应用程序中的性能影响。p> 有了这个谦逊的免责声明,一种方法是使用
标记将jQuery直接包含到React的主
index.html
页面中,这将使
$
在整个应用程序中全球可用:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <meta
      name="description"
      content="Web site created using create-react-app"
    />
    <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
    <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />

    <title>React App</title>

  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>

    <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
  </body>
</html>

工作示例。

这有点棘手,可能还有其他方法(也许更好)来实现相同的结果。此外,我将考虑将多个库加载到现有的反应应用程序中的性能影响。p> 有了这个谦逊的免责声明,一种方法是使用
标记将jQuery直接包含到React的主
index.html
页面中,这将使
$
在整个应用程序中全球可用:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <meta
      name="description"
      content="Web site created using create-react-app"
    />
    <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
    <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />

    <title>React App</title>

  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>

    <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
  </body>
</html>
工作示例