简体   繁体   English

index.js 文件如何与 index.html 通信?

[英]How index.js file is able to communicate with index.html?

In React project both index.html and index.js file are inside different folder and there is no link in between these two file.在 React 项目中 index.html 和 index.js 文件都在不同的文件夹中,这两个文件之间没有链接。 Then how we are able target div whose id is root of HTML file by using document.getElementById("root") inside index.js file.那么我们如何通过在 index.js 文件中使用 document.getElementById("root") 来定位 id 为 HTML 文件根目录的 div。

please answer this in easy language because i have just start learning this, I am compeletly begineer.请用简单的语言回答这个问题,因为我刚刚开始学习这个,我完全是初学者。

React is one of the best JS libraries out there. React 是目前最好的 JS 库之一。 It simplifies the development process without cluttering the implementation details explicitly.它简化了开发过程,而不会显式地混淆实现细节。 The index.html and index.js get linked during runtime when you start the script.当您启动脚本时, index.htmlindex.js会在运行时链接。 React uses webpack under the hood where the entry for the webpack is index.js and when it is run(after all the conversions) it injects the javascript code in the HTML file which is index.html . React uses webpack under the hood where the entry for the webpack is index.js and when it is run(after all the conversions) it injects the javascript code in the HTML file which is index.html . And you can see this injected code in the index.html when you build the bundle inside the build folder.当您在构建文件夹中构建包时,您可以在index.html中看到注入的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM