create-react-app脚手架使用
1.安装脚手架和路由
npm i -g create-react-app
npm i -S react-router react-router-dom
2.创建新项目
create-react-app 项目名称
3.运行项目
npm start
4.开始开发
跟vue-cli和ng-cli很不同的是,react就算用了cli和原来引入
1)书写组件
例如一个简单的组件:
//test.component.js
import React,{Component} from React
import './test.css' class Test extends Component {
constructor(...args){
super(...args)
}
render(){
return (
<div className="test">
test123
</div>
)
}
}
export default Test
2)引入书写路由
//App.js
import React,{Component} from React
import {BrowserRouter,Switch,Route,Link} from 'react-router-dom'
import Test1 from './test1.js'
import Test2 from './test2.js'
import Test3 from './test3.js' class App extends Component {
render(){
return (
<BrowserRouter>
<div>
<Link to="/test3/123/">切换到test3</Link>
<Test1></Test1>
<Switch>
<Route path="/" component={Test2}></Route>
<Route path="/test3/:id/" component={Test3}></Route>
</Switch>
</div>
</BrowserRouter>
)
}
}
export default App
3)ajax请求用es6的fetch
//组件挂载完成时访问接口
async componentDidMount(){
let data = await (await fetch('http://localhost:8088/api/getData',
// options
{ method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
user: 'miemie',
pass: '123456'
})
}
).json())
this.setState({myList: data})
}
create-react-app脚手架使用的更多相关文章
- tap news:week5 0.0 create react app
参考https://blog.csdn.net/qtfying/article/details/78665664 先创建文件夹 安装create react app 这个脚手架(facebook官方提 ...
- 如何扩展 Create React App 的 Webpack 配置
如何扩展 Create React App 的 Webpack 配置 原文地址https://zhaozhiming.github.io/blog/2018/01/08/create-react-a ...
- 在 .NET Core 5 中集成 Create React app
翻译自 Camilo Reyes 2021年2月22日的文章 <Integrate Create React app with .NET Core 5> [1] Camilo Reyes ...
- 使用create react app教程
This project was bootstrapped with Create React App. Below you will find some information on how to ...
- 深入 Create React App 核心概念
本文差点难产而死.因为总结的过程中,多次怀疑本文是对官方文档的直接翻译和简单诺列:同时官方文档很全面,全范围的介绍无疑加深了写作的心智负担.但在最终的梳理中,发现走出了一条与众不同的路,于是坚持分享出 ...
- Create React App
Facebook开源了React前端框架(MIT Licence),也同时提供了React脚手架 - create-react-app. create-react-app遵循约定优于配置(Coc)的原 ...
- Create React App 安装less 报错
执行npm run eject 暴露模块 安装 npm i less less-loader -D 1.打开 react app 的 webpack.config.js const sassRege ...
- [React] Use the Fragment Short Syntax in Create React App 2.0
create-react-app version 2.0 added a lot of new features. One of the new features is upgrading to Ba ...
- [React] {svg, css module, sass} support in Create React App 2.0
create-react-app version 2.0 added a lot of new features. One of the new features is added the svgr ...
- create react app 项目部署在Spring(Tomcat)项目中
网上看了许多,大多数都是nginx做成静态项目,但是这样局限性太多,与Web项目相比许多服务端想做的验证都很麻烦,于是开始了艰难的探索之路,终于在不经意间试出来了,一把辛酸... 正常的打包就不说了. ...
随机推荐
- 升级webpack2
更新:webpack3已经出来了,官方说从2到升级到3不用改一行配置,98%的人没有错误. 项目中用的是webpack1.webpack2已经出来一段时间了.决定升级.其实改动不是很大.修改加测试共花 ...
- libgdx学习记录17——照相机Camera
照相机在libgdx中的地位举足轻重,贯穿于整个游戏开发过程的始终.一般我们都通过Stage封装而间接使用Camera,同时我们也可以单独使用Camera以完成背景的移动.元素的放大.旋转等操作. C ...
- 《Effective Java》学习笔记 —— 通用程序设计
本章主要讨论局部变量.控制结构.类库.反射.本地方法的用法及代码优化和命名惯例. 第45条 将局部变量的作用域最小化 * 在第一次使用的它的地方声明局部变量(就近原则). * 几乎每个局部变量的声明都 ...
- harbor使用和管理
一.上传本地镜像到harbor中 先在harbor 中创建testdocker 项目 因为我们本地没有镜像,我们先拉取一个镜像,然后进行下面的操作 查看nginx 镜像 2.下载nginx镜像到本地 ...
- 初识Redux Middleware
前言 原先改变store是通过dispatch(action) = > reducer:那Redux的Middleware是什么呢?就是dispatch(action) = > reduc ...
- 微软职位内部推荐-Senior NLP Scientist
微软近期Open的职位: Job Title: Senior NLP Scientist Location: Suzhou, China Suzhou, one of the most vibrant ...
- springmvc 事务回滚说明
Spring中的@Transactional(rollbackFor = Exception.class)属性详解 序言 今天我在写代码的时候,看到了.一个注解@Transactional(rollb ...
- PAT甲题题解-1124. Raffle for Weibo Followers-模拟,水题
水题一个,贴个代码吧. #include <iostream> #include <cstdio> #include <algorithm> #include &l ...
- LeetCode 617. Merge Two Binary Trees合并二叉树 (C++)
题目: Given two binary trees and imagine that when you put one of them to cover the other, some nodes ...
- Alpha 贡献分及转会人员确定
贡献分如下: 转会人员:金东禾 转到队伍:bugphobia