React筆記:快速構建腳手架(1)

1. Create React APP

  React官方提供的腳手架工程Create React App:https://github.com/facebook/create-react-appcss

  Create React App基於最佳實踐,將Webpack、Babel、ESLint等工具的配置進行封裝。react

1.1 安裝

  全局安裝:git

npm install -g create-react-app

1.2 建立應用

npx create-react-app libing.react

1.3 運行應用

cd libing.react
npm start

  應用啓動成功後,在瀏覽器中打開http://localhost:3000/,便可訪問應用。github

1.4 HelloWorld組件

  新增組件:src/components/HelloWorld.jsnpm

import React, { Component } from "react"

class HelloWorld extends Component {
    render() {
        return ( 
            <div> Hello World! </div>
        );
    }
}

export default HelloWorld;

  修改App.js瀏覽器

import React, { Component } from 'react';
import logo from './logo.svg';
import HelloWorld from './components/HelloWorld'
import './App.css';

class App extends Component {
  render() {
    return (
      <div className="App">
        <header className="App-header">
          <img src={logo} className="App-logo" alt="logo" />
          <HelloWorld />
        </header>
      </div>
    );
  }
}

export default App;

相關文章
相關標籤/搜索