一、全局安装 npm install create-react-app -g
二、切换到目标目录 create-react-app name
三、进入项目文件夹 cd name
四、npm start
![]() |
|
- html>
- <html lang="en">
- <head>
- <meta charset="utf-8" />
-
- <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
-
-
- <meta name="viewport" content="width=device-width, initial-scale=1" />
-
- <meta name="theme-color" content="#000000" />
-
- <meta
- name="description"
- content="Web site created using create-react-app"
- />
-
- <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
-
-
- <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
-
- <title>React Apptitle>
- head>
- <body>
-
- <noscript>You need to enable JavaScript to run this app.noscript>
-
- <div id="root">div>
- body>
- html>
- import './App.css';
-
- function App() {
- return (
- <div className="App">
- App
- div>
- );
- }
-
- export default App;
- // 相当于 main.js
-
- import React from 'react';
- import ReactDOM from 'react-dom/client';
- import './index.css';
- import App from './App';
- import reportWebVitals from './reportWebVitals';
-
- const root = ReactDOM.createRoot(document.getElementById('root'));
- root.render(
- // React.StrictMode 标签 严格模式 检查
- <React.StrictMode>
- <App />
- React.StrictMode>
- );
-
- // 页面性能分析 需要 web-vitals库的支持
- reportWebVitals();