[英]How to add a 3rd party Jquery Library in React Functionnal component?
我只想在 React 应用程序中为我的主页使用第三个库。 问题是:该库是用 Jquery 开发的: www.npmjs.com/package/fullview
我需要导入:Jquery、js 文件和 css 文件。
到目前为止,我还没有找到将这种类型的库导入功能组件的任何方法。 仅 class 组件。
我可以直接在 index.html 中导入这些文件吗?或者我需要使用 import... from "..." 将它们导入到我的组件中
谢谢 !
您可以在 public/index.html 中添加 jquery CDN,如下所示:
//public/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.5.1.min.js"
crossorigin="anonymous"
></script>
</body>
</html>
无需在组件或其他东西中导入 jquery 现在 jquery 可以在全球范围内使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.