How to use react with antd components to implement a management system
This time I will show you how to use react with antd components to implement the management system, and what are the precautions for using react with antd components to implement the management system. 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 do not 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 block 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:
How to use vue to implement SMS verification performance optimizationUse vue-i18 plug-in in Vue to achieve Multi-language switchingThe above is the detailed content of How to use react with antd components to implement a management system. For more information, please follow other related articles on the PHP Chinese website!

JavaScript originated in 1995 and was created by Brandon Ike, and realized the language into C. 1.C language provides high performance and system-level programming capabilities for JavaScript. 2. JavaScript's memory management and performance optimization rely on C language. 3. The cross-platform feature of C language helps JavaScript run efficiently on different operating systems.

JavaScript runs in browsers and Node.js environments and relies on the JavaScript engine to parse and execute code. 1) Generate abstract syntax tree (AST) in the parsing stage; 2) convert AST into bytecode or machine code in the compilation stage; 3) execute the compiled code in the execution stage.

The future trends of Python and JavaScript include: 1. Python will consolidate its position in the fields of scientific computing and AI, 2. JavaScript will promote the development of web technology, 3. Cross-platform development will become a hot topic, and 4. Performance optimization will be the focus. Both will continue to expand application scenarios in their respective fields and make more breakthroughs in performance.

Both Python and JavaScript's choices in development environments are important. 1) Python's development environment includes PyCharm, JupyterNotebook and Anaconda, which are suitable for data science and rapid prototyping. 2) The development environment of JavaScript includes Node.js, VSCode and Webpack, which are suitable for front-end and back-end development. Choosing the right tools according to project needs can improve development efficiency and project success rate.

Yes, the engine core of JavaScript is written in C. 1) The C language provides efficient performance and underlying control, which is suitable for the development of JavaScript engine. 2) Taking the V8 engine as an example, its core is written in C, combining the efficiency and object-oriented characteristics of C. 3) The working principle of the JavaScript engine includes parsing, compiling and execution, and the C language plays a key role in these processes.

JavaScript is at the heart of modern websites because it enhances the interactivity and dynamicity of web pages. 1) It allows to change content without refreshing the page, 2) manipulate web pages through DOMAPI, 3) support complex interactive effects such as animation and drag-and-drop, 4) optimize performance and best practices to improve user experience.

C and JavaScript achieve interoperability through WebAssembly. 1) C code is compiled into WebAssembly module and introduced into JavaScript environment to enhance computing power. 2) In game development, C handles physics engines and graphics rendering, and JavaScript is responsible for game logic and user interface.

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.


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

Atom editor mac version download
The most popular open source editor

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

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.

Zend Studio 13.0.1
Powerful PHP integrated development environment
