[英]How to add a 3rd party Jquery Library in React Functionnal component?
I want to use a 3rd library only for my homepage in a React application.我只想在 React 应用程序中为我的主页使用第三个库。 The problem is: the library is developed with Jquery: www.npmjs.com/package/fullview
问题是:该库是用 Jquery 开发的: www.npmjs.com/package/fullview
I need to import: Jquery, js file and css file.我需要导入:Jquery、js 文件和 css 文件。
so far, I haven't found any way to import this type of library into a functionnal component.到目前为止,我还没有找到将这种类型的库导入功能组件的任何方法。 Only class components.
仅 class 组件。
Can I import these files directly in index.html with or i need to import them in my component with import... from "..."我可以直接在 index.html 中导入这些文件吗?或者我需要使用 import... from "..." 将它们导入到我的组件中
Thank you !谢谢 !
You can add jquery CDN in your public/index.html like this:您可以在 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>
no need to import jquery in component or something else now jquery is avalible golobally.无需在组件或其他东西中导入 jquery 现在 jquery 可以在全球范围内使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.