最佳答案
我最近开始反应。
我的 Html包含
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<title>React App</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
和 Index.js包含
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import './index.css';
ReactDOM.render(
<App />,
document.getElementById('root')
);
我怀疑我没有在 index.html
的任何脚本标签中提到 index.js
。但是它是如何引用 index.html
中的 root
div 元素的呢?我想知道,因为它是工作良好。请解释一下。
我运行这些命令来创建这个应用程序
npm install -g create-react-app
create-react-app hello-world
cd hello-world
npm start