TS+React+Mobx+Antd+Axios快速配置

2021/9/23 23:10:50

本文主要是介绍TS+React+Mobx+Antd+Axios快速配置,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

基本操作

# ★★★前提条件(可以运行create-react-app和yarn)★★★

# 创建项目(后面的操作记住进入项目根目录)
create-react-app 项目名 --template typescript

# 添加antd和axios
yarn add antd@3.22.0 axios@0.21.1

# 配置mobx(在TS中使用注解需要根据提示配置)
# 安装改变 create-react-app 中 webpack 配置插件
yarn add -D react-app-rewired customize-cra @babel/plugin-proposal-decorators 

# 在项目根目录下创建 config-overrides.js 并写入以下内容
const { override, addDecoratorsLegacy } = require("customize-cra")

module.exports = override(
  addDecoratorsLegacy()
)

# 修改 package.json 文件中 scripts 脚本
#原本配置
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
#新配置
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test --env=jsdom",
# end 修改 package.json 文件中 scripts 脚本

# 添加mobx和mobx-react
yarn add mobx@3.6.2 mobx-react@4.4.3 
# end 配置mobx

...其他配置...
# end 创建项目

目录结构

#React项目规范
src
  *components
  *models
  *pages
  *stores
   constants
   utils

#详解:
components 存放公共组件,每个组件一个文件(首字母大写)
models 	   存放后端接口
pages	   存放展示页面,每个页面一个文件(首字母大写)
stores     保存全局状态,里面文件(首字母大写)
constants  存放常量
utils      存放工具类
#React项目文件结构说明 end


这篇关于TS+React+Mobx+Antd+Axios快速配置的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程