<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當(dāng)前位置: 首頁 - 科技 - 知識(shí)百科 - 正文

        如何使用react配合antd組件實(shí)現(xiàn)管理系統(tǒng)

        來源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-27 19:41:55
        文檔

        如何使用react配合antd組件實(shí)現(xiàn)管理系統(tǒng)

        如何使用react配合antd組件實(shí)現(xiàn)管理系統(tǒng):這次給大家?guī)砣绾问褂胷eact配合antd組件實(shí)現(xiàn)管理系統(tǒng),使用react配合antd組件實(shí)現(xiàn)管理系統(tǒng)的注意事項(xiàng)有哪些,下面就是實(shí)戰(zhàn)案例,一起來看一下。使用create-react-app腳手架具體基礎(chǔ)配置請(qǐng)參考配合antd組件實(shí)現(xiàn)的管理系統(tǒng)demo,線上地址開發(fā)前反思1.
        推薦度:
        導(dǎo)讀如何使用react配合antd組件實(shí)現(xiàn)管理系統(tǒng):這次給大家?guī)砣绾问褂胷eact配合antd組件實(shí)現(xiàn)管理系統(tǒng),使用react配合antd組件實(shí)現(xiàn)管理系統(tǒng)的注意事項(xiàng)有哪些,下面就是實(shí)戰(zhàn)案例,一起來看一下。使用create-react-app腳手架具體基礎(chǔ)配置請(qǐng)參考配合antd組件實(shí)現(xiàn)的管理系統(tǒng)demo,線上地址開發(fā)前反思1.
        這次給大家?guī)砣绾问褂胷eact配合antd組件實(shí)現(xiàn)管理系統(tǒng),使用react配合antd組件實(shí)現(xiàn)管理系統(tǒng)的注意事項(xiàng)有哪些,下面就是實(shí)戰(zhàn)案例,一起來看一下。

        使用create-react-app腳手架

        具體基礎(chǔ)配置請(qǐng)參考

        配合antd組件實(shí)現(xiàn)的管理系統(tǒng)demo,線上地址

        開發(fā)前反思

        1. 按需加載

        webpack的 import 動(dòng)態(tài)加載的模塊的函數(shù),import(參數(shù)),參數(shù)為模塊地址。

        注意: import 后會(huì)返回一個(gè)promise對(duì)象。

        import('/components/chart').then(mud => {
         dosomething(mod)
        });

        本demo構(gòu)建了異步加載組件Bundle,具體代碼請(qǐng)見

        class Bundle extends Component {
         constructor(props) {
         super(props);
         this.state = {
         mod: null
         };
         }
         unmount = false
         componentDidMount = () => {
         // 加載組件時(shí),打開全局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對(duì)象; mod.default導(dǎo)出默認(rèn)
         props.load().then((mod) => {
         if (this.unmount) {
         // 離開組件時(shí),不異步執(zhí)行setState
         this.props.dispatch(loading(false))
         return false
         }
         this.setState({
         mod: mod.default ? mod.default : mod
         }, _ => {
         // 組件加載完畢,關(guān)閉loading
         this.props.dispatch(loading(false))
         });
         });
         }
         render() {
         return this.state.mod ? this.props.children(this.state.mod) : null;
         }
        }

        具體使用

        <Bundle load={() => import('路徑')}>
         {Comp => {
         return Comp ? <Comp /> : <p>加載中...</p>
         }}
         </Bundle>

        2. 全局loading

        配合redux,dispatch => reducer更新 => mapstate更新,在根組件進(jìn)行l(wèi)oading的渲染

        詳細(xì)請(qǐng)見本demo地址 src/routers/router.js——render函數(shù)

        3. 配置路由對(duì)象

        項(xiàng)目布局如下

        本demo使用的是router4,官方文檔演示為單行Route(如vue種的router),未有統(tǒng)一配置對(duì)象。 管理系統(tǒng)基本圍繞著content進(jìn)行業(yè)務(wù)開發(fā),構(gòu)建通用配置有助于開發(fā) 構(gòu)建router.config.js

        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: '多級(jí)菜單',
         menuIco: 'setting',
         children: [
         {
         menuName: '多級(jí)菜單2',
         children: [
         {
         menuName: '菜單',
         component: 'user/list.js', // 主頁
         path: '/admin/user/list3' // 主頁
         }
         ]
         }
         ]
         },
         {
         menuName: '關(guān)于我',
         menuIco: 'smile-o',
         component: 'about/about.js', // 主頁
         path: '/admin/about' // 主頁
         }
        ]

        實(shí)現(xiàn)思路,最外層布局為Admin,content被Admin包裹,那么可以利用 this.props.children ,把內(nèi)容打入content中。(利用bundle組件異步加載后塞入組件進(jìn)行渲染)

        <Admin>
         <Content { ...this.props } breadcrumb={this.state.breadcrumb}>
         {this.props.children}
         </Content>
        </Admin>
        // Content組件內(nèi)部
        render() {
         return (
         <p> 
         {this.props.children}
         </p>
         )
        }
        // 本demo實(shí)現(xiàn),詳見src/routers/router.js
        <Route
         path="/admin"
         render={item => (
         <Admin {...item} { ...this.props }>
         {initRouters.map(el => this.deepItem(el, { ...this.props, ...item}))}
         </Admin>
         )}
        />

        4. 配置通用reducer

        多人配合開發(fā),一些業(yè)務(wù)場(chǎng)景的組件需要狀提升(不理解狀態(tài)提升的同學(xué),請(qǐng)科學(xué)上網(wǎng))

        import otherReducers from './otherReducers'
        const App = combineReducers({
         rootReducers,
         ...otherReducers // 其他需要增加的reducers
        })

        5. 登陸驗(yàn)證

        利用 withRouter 函數(shù),頁面進(jìn)行路由跳轉(zhuǎn)時(shí)觸發(fā)該函數(shù)

        const newWithRouter = withRouter(props => {
         // ....
        })

        若未登錄,則返回

        return <Redirect to="/login" />

        6. 路由攔截

        同上,根據(jù)路由配置與權(quán)限,返回相應(yīng)的菜單或屏蔽

        return <Redirect to={其他} />

        7 其他配置

        7-1. 自定義樣式

        // 修改webpack.config.dev.js 和 webpack.config-prod.js 配置文件
        {
         test: /\.(css|less)$/,
         // 匹配src的都自動(dòng)加載css-module
         include: [/src/],
         exclude: [/theme/],
         use: [
         require.resolve('style-loader'), {
         loader: require.resolve('css-loader'),
         options: {
         importLoaders: 1,
         modules: true, // 新增對(duì)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 < 9', // React doesn't support IE8 anyway
         ],
         flexbox: 'no-2009'
         })
         ]
         }
         }, {
         loader: require.resolve('less-loader') // compiles Less to CSS
         }
         ]
        }, {
         // 不匹配node_modules,theme的都不能自動(dòng)加載css-module
         test: /\.(css|less)$/,
         include: [/node_modules/,/theme/],
         use: [
         {
         loader: "style-loader"
         }, {
         loader: "css-loader",
         options: {
         importLoaders: 1
         }
         }, {
         loader: require.resolve('less-loader') // compiles Less to CSS
         }
         ]
        },

        使用: 在App.js中直接導(dǎo)入

        import './assets/theme/App.less'

        7-2. 熱更新

        步驟一:

        // 安裝react-hot-loader 
        npm install --save-dev react-hot-loader

        步驟二:

        在webpack.config.js 的 entry 值里加上 react-hot-loader/patch

        步驟三:

        webpackDevServer.config.js中hot設(shè)置為true

        步驟四: 在webpack.config.dev.js中在babel-loader中plugins加入react-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'
         ]
         }
        },

        步驟五:

        重寫index.js,App掛載

        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. 本地瀏覽

        直接在package.json中 加入

        homepage:'.'

        后記:使用react與vue的感悟

        react是函數(shù)式編程,代碼難度、學(xué)習(xí)曲度、裝逼指數(shù),社區(qū)生態(tài)多樣性相比vue更高一點(diǎn)。

        vue提供了大量的指令降低了開發(fā)難度,詳細(xì)完善的文檔,上手更快。

        react提供較少的api,相比vue的指令,業(yè)務(wù)場(chǎng)景的功能需要自己實(shí)現(xiàn),難度更高一點(diǎn)

        vue適合中小型項(xiàng)目,單兵、少量人員配合快速開發(fā)

        react適合大型項(xiàng)目,多人協(xié)作

        相信看了本文案例你已經(jīng)掌握了方法,更多精彩請(qǐng)關(guān)注Gxl網(wǎng)其它相關(guān)文章!

        推薦閱讀:

        如何使用vue實(shí)現(xiàn)短信驗(yàn)證性能優(yōu)化

        在Vue中使用vue-i18插件實(shí)現(xiàn)多語言切換

        聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        如何使用react配合antd組件實(shí)現(xiàn)管理系統(tǒng)

        如何使用react配合antd組件實(shí)現(xiàn)管理系統(tǒng):這次給大家?guī)砣绾问褂胷eact配合antd組件實(shí)現(xiàn)管理系統(tǒng),使用react配合antd組件實(shí)現(xiàn)管理系統(tǒng)的注意事項(xiàng)有哪些,下面就是實(shí)戰(zhàn)案例,一起來看一下。使用create-react-app腳手架具體基礎(chǔ)配置請(qǐng)參考配合antd組件實(shí)現(xiàn)的管理系統(tǒng)demo,線上地址開發(fā)前反思1.
        推薦度:
        • 熱門焦點(diǎn)

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 亚洲AV午夜成人片| 在线亚洲精品自拍| 国产成人亚洲合集青青草原精品| 国产永久免费高清在线| 久久亚洲精品专区蓝色区| 美丽姑娘免费观看在线观看中文版| 亚洲AV无码码潮喷在线观看| 免费看男人j放进女人j免费看| 国产一区二区视频免费| 亚洲黄色在线观看视频| 国产AV无码专区亚洲AV琪琪| 性做久久久久免费看| 男人扒开添女人下部免费视频| 免费在线观看视频a| 亚洲国产成人99精品激情在线| 成人影片麻豆国产影片免费观看| 亚洲一区二区三区写真| 国产aa免费视频| 精品多毛少妇人妻AV免费久久| 国产极品美女高潮抽搐免费网站| 亚洲国产中文在线二区三区免| 扒开双腿猛进入爽爽免费视频| 亚洲精品中文字幕麻豆| 亚洲免费人成在线视频观看| 国产亚洲美女精品久久久久狼| 一级做a爰片久久毛片免费陪| 国产亚洲精品一品区99热| 18女人水真多免费高清毛片| 亚洲综合国产成人丁香五月激情| 亚洲 小说区 图片区 都市| 在线涩涩免费观看国产精品| 亚洲av片不卡无码久久| 亚洲福利中文字幕在线网址| 3344永久在线观看视频免费首页| 亚洲AV一区二区三区四区| 亚洲精品美女久久久久99| 少妇高潮太爽了在线观看免费| 一级毛片完整版免费播放一区| 亚洲综合久久久久久中文字幕| 最好免费观看韩国+日本| 亚洲卡一卡2卡三卡4麻豆|