admin管理员组文章数量:1421732
I have created one js file in our application. in this js file How add in our page?
I had Written below code for our application. First of I had written online link that's work perfect. then after download js and set path to js file. but not proper working.
ponentDidMount() {
const script = document.createElement("script");
// script.src = ".12.4.min.js";
script.src = "../../Content/JS/jquery-1.12.4.min.js";
script.async = true;
document.body.appendChild(script);
}
I have created one js file in our application. in this js file How add in our page?
I had Written below code for our application. First of I had written online link that's work perfect. then after download js and set path to js file. but not proper working.
ponentDidMount() {
const script = document.createElement("script");
// script.src = "https://code.jquery./jquery-1.12.4.min.js";
script.src = "../../Content/JS/jquery-1.12.4.min.js";
script.async = true;
document.body.appendChild(script);
}
Share Improve this question asked Jan 7, 2019 at 6:19 Diamond KingDiamond King 67610 silver badges17 bronze badges 5-
install those packages by
npm install {package name}
– Vikas Singh Commented Jan 7, 2019 at 6:21 - which one package install ?? – Diamond King Commented Jan 7, 2019 at 6:23
-
as i can see you want to use Jquery in project then you can install it by
npm install --save jquery
or through your package manager – Vikas Singh Commented Jan 7, 2019 at 6:25 - I have already install this package. but can't add to external js file. – Diamond King Commented Jan 7, 2019 at 6:32
- put js file within src folder and import this file and put it in script tag anywhere inside your project. – Mustkeem K Commented Jan 7, 2019 at 6:34
2 Answers
Reset to default 2If you want to add additional js file (script). This is the easiest way to to do this.
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<script src="../../Content/JS/jquery-1.12.4.min.js"></script>
</body>
This is the root html file of your react application. According to your folder structure path can be changed.
You need to install and then import jQuery or any other plugin you need in your ponent.
npm install {package name}
in your package JSON.
import jquery from 'jquery'
in your ponent
Here is an example
本文标签: javascriptHow to add external js file in react applicationStack Overflow
版权声明:本文标题:javascript - How to add external js file in react application? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745345344a2654453.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论