[英]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.