This time I will bring you react to cooperate with antd components to make a backend system, and react to use antd components to make a backend system. What are the precautions?The following is a practical case, let's take a look.
Using create-react-app scaffolding
For specific basic configuration, please refer to
Management system demo implemented with antd components, online address
Reflection before development
1. Load on demand
webpack's import function of dynamically loaded modules, import (parameter), the parameter is the module address.
Note: A promise object will be returned after import.
import('/components/chart').then(mud => { dosomething(mod) });
This demo builds an asynchronous loading component Bundle. For specific codes, please see
class Bundle extends Component { constructor(props) { super(props); this.state = { mod: null }; } unmount = false componentDidMount = () => { // 加载组件时,打开全局loading this.props.dispatch(loading(true)) this.load(this.props) } componentWillUnmount = () => { this.unmount = true } componentWillReceiveProps(nextProps) { if (nextProps.load !== this.props.load) { this.load(nextProps) } } load(props) { if (this.state.mod) { return true } //注意这里,使用Promise对象; mod.default导出默认 props.load().then((mod) => { if (this.unmount) { // 离开组件时,不异步执行setState this.props.dispatch(loading(false)) return false } this.setState({ mod: mod.default ? mod.default : mod }, _ => { // 组件加载完毕,关闭loading this.props.dispatch(loading(false)) }); }); } render() { return this.state.mod ? this.props.children(this.state.mod) : null; } }
Specific usage
<bundle> import('路径')}> {Comp => { return Comp ? <comp></comp> : <p>加载中...</p> }} </bundle>
2. Global loading
With redux, dispatch => reducer update => mapstate update, load rendering in the root component
For details, please see this demo address src/routers/router.js——render function
3. Configure routing objects
The project layout is as follows
const routers = [ { menuName: '主页', menuIco: 'home', component: 'home/home.js', // 主页 path: '/admin/home' // 主页 }, { menuName: '用户', menuIco: 'user', children: [ { menuName: '用户列表', component: 'user/list.js', // 主页 path: '/admin/user/list' // 主页 } ] }, { menuName: '多级菜单', menuIco: 'setting', children: [ { menuName: '多级菜单2', children: [ { menuName: '菜单', component: 'user/list.js', // 主页 path: '/admin/user/list3' // 主页 } ] } ] }, { menuName: '关于我', menuIco: 'smile-o', component: 'about/about.js', // 主页 path: '/admin/about' // 主页 } ]to implement the idea. The outermost layout is Admin, and the content is wrapped by Admin, then you can use this. props.children, enter the content into content. (Use the bundle component to be loaded asynchronously and then inserted into the component for rendering)
<admin> <content> {this.props.children} </content> </admin> // Content组件内部 render() { return ( <p> {this.props.children} </p> ) } // 本demo实现,详见src/routers/router.js <route> ( <admin> {initRouters.map(el => this.deepItem(el, { ...this.props, ...item}))} </admin> )} /></route>
4. Configure a general reducer
For multiple people to cooperate in development, the components of some business scenarios need to be improved. (Students who don’t understand status improvement, please surf the Internet scientifically)import otherReducers from './otherReducers' const App = combineReducers({ rootReducers, ...otherReducers // 其他需要增加的reducers })
5. Login verification
Use the withRouter function, which is triggered when the page performs routing jumpconst newWithRouter = withRouter(props => { // .... })If you are not logged in, return to
return <redirect></redirect>
6. Routing interception
Same as above, return to the corresponding menu or shield based on routing configuration and permissionsreturn <redirect></redirect>
7 Other configurations
7-1. Custom style// 修改webpack.config.dev.js 和 webpack.config-prod.js 配置文件 { test: /\.(css|less)$/, // 匹配src的都自动加载css-module include: [/src/], exclude: [/theme/], use: [ require.resolve('style-loader'), { loader: require.resolve('css-loader'), options: { importLoaders: 1, modules: true, // 新增对css modules的支持 localIdentName: '[path]_[name][local]_[hash:base64:5]' } }, { loader: require.resolve('postcss-loader'), options: { // Necessary for external CSS imports to work // https://github.com/facebookincubator/create-react-app/issues/2677 ident: 'postcss', plugins: () => [ require('postcss-flexbugs-fixes'), autoprefixer({ browsers: [ '>1%', 'last 4 versions', 'Firefox ESR', 'not ie Usage: Directly import <p style="text-align: left;"></p><pre class="brush:php;toolbar:false">import './assets/theme/App.less'in App.js 7-2. Hot updateStep 1:
// 安装react-hot-loader npm install --save-dev react-hot-loaderStep 2:Add react-hot-loader/patch# to the entry value of webpack.config.js
##Step 3:
Set hot to true in webpackDevServer.config.js
Step 4: Add react to plugins in babel-loader in webpack.config.dev.js -hot-loader/babel
{ test: /\.(js|jsx|mjs)$/, include: paths.appSrc, loader: require.resolve('babel-loader'), options: { // This is a feature of `babel-loader` for webpack (not Babel itself). It // enables caching results in ./node_modules/.cache/babel-loader/ directory for // faster rebuilds. cacheDirectory: true, plugins: [ 'react-hot-loader/babel' ] } },
Step 5:
Rewrite index.js, App mount
import { AppContainer } from 'react-hot-loader' const render = Component => { ReactDOM.render( <appcontainer> <component></component> </appcontainer>, document.getElementById('root') ) } render(App) if(module.hot) { module.hot.accept('./App',() => { render(App); }); }
7-3. Local browsing
Add
homepage:'.'
directly to package.json Postscript: Insights on using react and vue
react is functional programming, code difficulty, learning curve, pretentiousness index, community ecological diversity are related A bit higher than vue.
vue provides a large number of instructions to reduce the difficulty of development, and detailed and complete documentation makes it faster to get started.
react provides fewer APIs. Compared with vue's instructions, the functions of business scenarios need to be implemented by yourself, which is more difficult.
vue is suitable for small and medium-sized projects, and can be quickly coordinated by a single soldier or a small number of people. Development
react is suitable for large-scale projects, multi-person collaboration
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!
Recommended reading:
What are the ways to convert images to base64 in jsVue beforeEnter uses hook functionThe above is the detailed content of React cooperates with antd components to create a backend system. For more information, please follow other related articles on the PHP Chinese website!

JavaScript is widely used in websites, mobile applications, desktop applications and server-side programming. 1) In website development, JavaScript operates DOM together with HTML and CSS to achieve dynamic effects and supports frameworks such as jQuery and React. 2) Through ReactNative and Ionic, JavaScript is used to develop cross-platform mobile applications. 3) The Electron framework enables JavaScript to build desktop applications. 4) Node.js allows JavaScript to run on the server side and supports high concurrent requests.

Python is more suitable for data science and automation, while JavaScript is more suitable for front-end and full-stack development. 1. Python performs well in data science and machine learning, using libraries such as NumPy and Pandas for data processing and modeling. 2. Python is concise and efficient in automation and scripting. 3. JavaScript is indispensable in front-end development and is used to build dynamic web pages and single-page applications. 4. JavaScript plays a role in back-end development through Node.js and supports full-stack development.

C and C play a vital role in the JavaScript engine, mainly used to implement interpreters and JIT compilers. 1) C is used to parse JavaScript source code and generate an abstract syntax tree. 2) C is responsible for generating and executing bytecode. 3) C implements the JIT compiler, optimizes and compiles hot-spot code at runtime, and significantly improves the execution efficiency of JavaScript.

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools