T

templateReact

模版

运行

 yarn start
 npm run start //开发
 yarn build   
 npm run build  //打包

依赖

  • axios
  • redux
  • react-router-dom #### axios 使用 > service中重新定义GET POST
import $http from "../../service"; //页面引入统一service
 $http.GET("/test")  
      .then(d=>{
          debugger
      })
      .catch(e=>{
          debugger
      })

redux 使用

页面引入redux的connct,采用装饰器模式过滤所需state

 import{connect} from "react-redux"; 
 @connect((state)=>{
   // debugger
    let {layout,login} = state
    return {layout,login};
})
 class Demo extends Component{}

页面修改redux,type类型为枚举类型,防止胡乱定义

import EVENT from "../../store/EVENT"
   this.props.dispatch({
            type:EVENT.LOGIN,
            payload:{ 
                name:"hehehe"
            }
        })

react-router-dom

页面中引入路由跳转,使用Link组件跳转和动态跳转

import {Link} from "react-router-dom"; //组件跳转
 this.props.history.push("/index2") //动态跳转