[英]How to import js file from src file into index.html?
我正在使用React創建一個系統,但我仍然是React的新手。 我需要在src文件夾中的js文件所在的index.html中添加js文件。 我需要導入此js文件才能使系統正常工作。 有人知道如何解決我的問題嗎? 提前致謝。
這就是我導入js文件的方式。 我認為我的路線有問題。 有誰知道導入我的js文件的正確路徑?
//index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<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="http://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script>
<script src="https://unpkg.com/@coreui/coreui/dist/js/coreui.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js" crossorigin></script>
<script type="text/javascript" src='../src/js/index.js'></script>
</body>
</html>
從上圖可以看到,我的index.js位於src文件夾下。
我認為這不是執行此操作的好方法。 您試圖將./src一些js文件添加到./public文件夾index.html
不推薦這種方式。 但是,如果要添加一些外部鏈接,請將其放在./public文件夾下並導入,但是不建議這樣做。
參考: 外部導入的示例項目
路徑應該是
<script src='../src/js/index.js'></script>
您需要將一個文件夾( '../'
)放在與public
和src
相同的位置,然后進入src/js/index.js
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.