美文网首页
React编程 - 1 - 使用create-react-app

React编程 - 1 - 使用create-react-app

作者: ElliotG | 来源:发表于2018-11-10 10:52 被阅读0次

1. React官方脚手架
Create React App
https://github.com/facebookincubator/create-react-app

1-1) install create-react-app
sudo npm install -g create-react-app

1-2) create new app
create-react-app my-app

1-3) run app
cd my-app
npm start

2. 什么是JSX
JSX是一种用于描述UI的JavaScript扩展语法, React使用这种语法描述组件的UI。

旧的前段开发模式:
为了做到UI和数据分离, 发明了模板技术。
大多数旧的前端框架都有自己的模板引擎。
如: jQuery template

但是,对于比较复杂的UI,利用模板语法维护起来有些力不从心。

3. 使用create-react-app模板创建的HelloWorld
package.json

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.6.1",
    "react-dom": "^16.6.1",
    "react-scripts": "2.1.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]
}

App.js

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

class App extends Component {
  render() {
    return (
      <div className="App">
        <header className="App-header">
          <img src={logo} className="App-logo" alt="logo" />
          <h1>Welcome to React</h1>
        </header>
        <p className="App-intro">
          Hello World
        </p>
      </div>
    );
  }
}

export default App;

效果如下


image.png

相关文章

网友评论

      本文标题:React编程 - 1 - 使用create-react-app

      本文链接:https://www.haomeiwen.com/subject/nmhzxqtx.html