【招聘App】—— React/Nodejs/MongoDB全栈项目:项目准备
前言:最近在学习Redux+react+Router+Nodejs全栈开发高级课程,这里对实践过程作个记录,方便自己和大家翻阅。最终成果github地址:https://github.com/66Web/react-antd-zhaoping,欢迎star。
一、项目概述

二、需求分析

- 文件架构和规范
- src目录:前端源码目录
- server目录:后端express目录
- 根据功能文件夹:component,container,reducers等
- router划分页面方式
- 进入应用时获取用户信息,用户未登录跳转login页面
- Login和reigster页面不需要权限认证
- 用户信息,聊天列表,职位列表页面共享底部tabbar
- 其它注意事项
- Mongodb字段设计
- axios发送异步请求
- redux管理所有数据,组件尽量用antd-mobile,弱化css
三、React开发环境
- Ceate-reacp-app脚手架生成文件格式
- 官网:https://github.com/facebookincubator/create-react-app
- 全局安装:
npm install -g create-react-app
- 新建项目:
create-react-app my-project
- 开启调试环境:
npm start
- 查看调试页面:浏览器访问localhost:3000
- 脚手架命令
- 安装第三方库redux:
npm install redux --save
- 弹出配置文件,自定义配置webpack:
npm run eject
- 扩展package.json里的script字段,扩展npm run命令
四、ES6常用语法
- ES6是新的JavaScript语法规范
- 使用babel语法转换器,支持低端浏览器
- 流行的库基本都属于ES6构建,React默认使用ES6新语法开发
- ES6语法概述:块级作用域、字符串、函数、对象扩展、解构、类、模块化
五、AntD-Mobile组件库
- 蚂蚁金服出品的UI组件库:antdesignPC端使用,ant-mobile移动端使用
- Ant Design Mobile:一个基于 Preact / React / React Native 的 UI 组件库
- 官网:https://mobile.ant.design/index-cn 【AntUI文档】
- 安装:
npm install antd-mobile --save
//或使用yarn更块
yarn add antd-mobile --save
- 使用组件
import {Button} from 'antd-mobile'
import 'antd-mobile/dist/antd-mobile.css' //全部加载 - 按需加载
- 安装babel-plugin-import(之后就可以不用引入css)
yarn add babel-plugin-import --save
- 配置:修改package.json中的bable项
"plugins":[
["import", { "libraryName": "antd-mobile", "style": "css" }] // `style: true` 会加载 less 文件
] - 个性化配置需要执行
npm run eject
- 兼容Web和ReactNative
- 常用组件:Import后可以直接使用
- Layout 布局组件
- 表单组件,数据展示组件,选择器等等
- 操作组件
六、前后端联调
- 使用axios发送异步请求
axios:简洁好用的发送请求库
npm install axios --save
- 如何发送:端口不一致,使用proxy配置转发
- package.json中:使用proxy统一端口
"proxy":"http://localhost:9093" //所有端口都转换到9093
- 获取数据(不使用redux的情况)
import axios from 'axios' constructor(props){
super(props)
this.state = {
data: {}
}
} componentDidMount(){
axios.get('/data')
.then(res => {
if(res.status == 200){
this.setState({data: res.data})
}
//console.log(res)
})
} <h2>我的名字是{this.state.data.user}</h2>
- 使用redux获取数据
- redux.js中:使用异步数据
import axios from 'axios' const USER_DATA = 'USER_DATA' const initState = {
user: '李云龙',
age: 20
}
export function auth(state=initState,action){
switch(action.type){
case USER_DATA:
return {...state, ...action.payload}
default:
return state
}
} //获取异步数据:axios.get,post发送请求,返回promise对象;Redux里获取数据,然后dispatch即可
export function getUserdata(){
//dispatch用来通知数据修改
return dispatch => {
axios.get('/data')
.then(res => {
if(res.status == 200){
dispatch(userData(res.data)
}
//console.log(res)
})
}
}
export function userData(data){
return {type:USER_DATA, payload:data}
} Auth.js中:渲染页面
import {connect} from 'react-redux' import {getUserData} from './Auth.redux' componentDidMount(){
this.props.getUserData()
} <h2>我的名字是{this.props.user},年龄{this.props.age}</h2> Auth = connect()(Auth)
export default Auth;
- axios拦截器,统一loading处理
config.js中:专门配置axios,Axios.interceptors设置拦截器,比如全局的loading
import axios from 'axios'
import {Toast} from 'antd-mobile' //轻提示 //拦截请求
axios.interceptors.request.use(function(config){
Toast.loading('加载中',0)
return config
}) //拦截响应
axios.interceptors.response.use(function(config){
Toast.hide()
return config
})index.js中:应用axios和antd配置
import './config'
import 'antd-mobile/dist/antd-mobile.css'
七、项目环境搭建
- 安装
yarn add antd-mobile babel-plugin-import axios express、
mongoose react-redux redux redux-thunk
redux-devtools-extension cookie-parser --saveyarn add babel-plugin-transform-decorators-legacy --save-dev
配置
"babel": {
"presets": [
"react-app"
],
"plugins": [
[
"import",
{
"libraryName": "antd-mobile",
"style": "css"
}
],
["@babel/plugin-proposal-decorators",
{ "legacy": true }
]
]
},
"proxy":"http://localhost:9093"reducer.js:合并所有reducer的文件
//合并所有reducer,并且返回
import {combineReducers} from 'redux' export default combineReducers({}) //暂无reducer
注:项目来自慕课网
【招聘App】—— React/Nodejs/MongoDB全栈项目:项目准备的更多相关文章
- 【招聘App】—— React/Nodejs/MongoDB全栈项目:登录注册
前言:最近在学习Redux+react+Router+Nodejs全栈开发高级课程,这里对实践过程作个记录,方便自己和大家翻阅.最终成果github地址:https://github.com/66We ...
- 【招聘App】—— React/Nodejs/MongoDB全栈项目:消息列表
前言:最近在学习Redux+react+Router+Nodejs全栈开发高级课程,这里对实践过程作个记录,方便自己和大家翻阅.最终成果github地址:https://github.com/66We ...
- 【招聘App】—— React/Nodejs/MongoDB全栈项目:socket.io&聊天实现
前言:最近在学习Redux+react+Router+Nodejs全栈开发高级课程,这里对实践过程作个记录,方便自己和大家翻阅.最终成果github地址:https://github.com/66We ...
- 【招聘App】—— React/Nodejs/MongoDB全栈项目:信息完善&用户列表
前言:最近在学习Redux+react+Router+Nodejs全栈开发高级课程,这里对实践过程作个记录,方便自己和大家翻阅.最终成果github地址:https://github.com/66We ...
- 【招聘App】—— React/Nodejs/MongoDB全栈项目:个人中心&退出登录
前言:最近在学习Redux+react+Router+Nodejs全栈开发高级课程,这里对实践过程作个记录,方便自己和大家翻阅.最终成果github地址:https://github.com/66We ...
- 一个 Vue & Node 的全栈小项目
约学 - 可以寻找一起自习的小伙伴的Web APP 一个基于 Vue & Node 的移动端全栈小项目 在线演示(请使用移动端查看效果) 源码地址: https://github.com/G- ...
- 基于NodeJS的全栈式开发
前言 为了解决传统Web开发模式带来的各种问题,我们进行了许多尝试,但由于前/后端的物理鸿沟,尝试的方案都大同小异.痛定思痛,今天我们重新思考了“前后端”的定义,引入前端同学都熟悉的 NodeJS,试 ...
- (转)也谈基于NodeJS的全栈式开发(基于NodeJS的前后端分离)
原文链接:http://ued.taobao.org/blog/2014/04/full-stack-development-with-nodejs/ 随着不同终端(pad/mobile/pc)的兴起 ...
- 也谈基于NodeJS的全栈式开发(基于NodeJS的前后端分离)
前言 为了解决传统Web开发模式带来的各种问题,我们进行了许多尝试,但由于前/后端的物理鸿沟,尝试的方案都大同小异.痛定思痛,今天我们重新思考了“前后端”的定义,引入前端同学都熟悉的NodeJS,试图 ...
随机推荐
- 【反演复习计划】【bzoj2154】Crash的数字表格
膜拜cdc……他的推导详细到我这种蒟蒻都能看得懂! 膜拜的传送门 所以我附一下代码就好了. #include<bits/stdc++.h> #define N 10000005 #defi ...
- Mysql启动服务提示系统找不到指定的文件
Mysql启动服务: C:\Windows\system32>net start mysql发生系统错误 2. 系统找不到指定的文件. 怎么还是报这个错?难道不是由于配置的原因?对,不是由于上面 ...
- css深入理解之border
1. border-width border-width不支持百分比,类似的还有outline,box-shadow,text-shadow等 border-width支持关键字:thin(1px, ...
- H5中使用Web Storage来存储结构化数据
在上一篇对Web Storage的介绍中,可以看到,使用Storage保存key—value对时,key.value只能是字符串,这对于简单的数据来说已经够了,但是如果需要保存更复杂的数据,比如保存类 ...
- mysql数据库设计之三范式
第一范式: 第二范式: 正解: 第三范式: 示例: 正解: BC范式: 示例: 正解:
- Codeforces 1023 D.Array Restoration-RMQ(ST)区间查询最值 (Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Fi)
D. Array Restoration 这题想一下就会发现是只要两个相同的数之间没有比它小的就可以,就是保存一下数第一次出现和最后一次出现的位置,然后查询一下这个区间就可以,如果有0的话就进行填充. ...
- Kattis - boxes (dfn序)
Boxes There are N boxes, indexed by a number from 1 to N . Each box may (or not may not) be put into ...
- 学习LSM(Linux security module)之三:Apparmor的前世今生和基本使用
感冒了,感觉一脑子浆糊,真是蛋疼. 先粗略讲一些前置知识. 一:MAC和DAC DAC(Discretionary Access Control),自主访问控制,是最常用的一类访问控制机制,意思为主体 ...
- [CF935F]Fafa and Array
法法round(雾 题意:给一个序列$a_{1\cdots n}$,定义$\begin{align*}f=\sum\limits_{i=1}^{n-1}\left|a_i-a_{i+1}\right| ...
- 【kd-tree】bzoj4066 简单题
同p1176. #include<cstdio> #include<cmath> #include<algorithm> using namespace std; ...