使用create-react-app創建一個簡單的react項目,會在項目的根目錄下生成一個入口文件index.js,其內容大致如下:ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById('root')
);上述代碼中,document.getElementById("root")這句就是把根組件掛載在根頁面中,該頁面位于項目的根目錄public/index.html,其內容大致如下:<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
</body>上述代碼中,<div id="root"></div>和document.getElementById("root")相對應. 我的問題是,在開發環境下沒有打包文件的情況下,index.js中的document.getElementById("root")是如何能夠關聯到另一個目錄public/index.html文件呢,這兩者之間好像沒有引用關系.
添加回答
舉報
0/150
提交
取消