




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
dva+umi的約定掌握生成?掌握redux異步方案-redux-generatorumiGeneratorES6提供的一種異步編程解決方案,語(yǔ)法行為與yieldGenerator函數(shù)里使用,在其他地方會(huì)報(bào)yieldyield}varhw由于Generator函數(shù)返回的遍歷?對(duì)象,只有調(diào)用next方法才會(huì)數(shù)。yieldredux-地址 /redux-saga/redux-安裝:npminstall--saveredux-importimportReact,{Component}fromimport{BrowserRouter,Switch,Link,Route}fromimportLoginPagefrom"./LoginPage";importUserPagefrom"./UserPage";importPrivatePagefrom"./PrivatePage";exportdefaultclassRouterPageextends{render(){return(<Routepath="/login"{LoginPage}{/*<Routepath="/user"{UserPage}/><PrivatePagepath="/user"{UserPage}}}importimport{createStore,combineReducers,applyMiddleware}from"redux";importthunkfrom"redux-thunk";constinitialLogin{isLogin:false,loading:false,name:"",error:functionloginReducer(state={...initialLogin},action){switch{casereturnloading:true,return{isLogin:true,}}conststorecreateStore(combineReducers({user:loginReducer}),applyMiddleware(thunk),exportdefaultimportReact,{Component}from"react";import{Redirect}from"react-router-dom";import{connect}from"react-exportdefaultstate=>({loading:{/*login:()=>type:}),login:()=>dispatch=>{dispatch({type:"requestLogin"});setTimeout(()=>{type:},classLoginPageextends{render()const{isLogin,loading,location,login}=if(isLogin)constconst{redirect="/"}=location.statereturn<Redirectto={redirect}}return<buttononClick={login}>{loading"登錄中...":"登錄"}</button>}importReact,{Component}fromimport{Route,Redirect}from"react-router-dom";import{connect}from"react-redux";exportdefaultstate=>({isLogin:classPrivatePageextends{render()const{path,component,isLogin}if(isLogin)returnreturn<Routepath={path}{component}}returnpathname:"/login",state:{redirect:path},}call:調(diào)用異步操作put:狀態(tài)更新takeEvery:做importimport{call,put,takeEvery}from"redux-constUserService{login(name)returnnewPromise((resolve,reject){console.log("omg");setTimeout(()=>{if(name==="{resolve({name:""}else}},//workertry{yieldput({type:"requestLogin"});constres=yieldcall(UserService.login,type:"requestSuccess",}{type:"requestFailure",}}//watchersagafunction*mySaga(){yieldtakeEvery("login",}exportdefaultconstconstinitialLogin=isLogin:false,loading:false,name:"",error:exportdefaultfunctionloginReducer(state=...initialLogin},{console.log("action",action);switch(action.type){return{loading:true,return{isLogin:true,return{isLogin:false,loading:false,}}3.redux-import{createStore,combineReducers,applyMiddleware}from"redux";//importthunkfrom"redux-importcreateSagaMiddlewarefrom"redux-saga";importmySagafrom"./mySaga";importloginReducerfrom"./user.redux";constsagaMiddleware=createSagaMiddleware();conststorecreateStore(combineReducers({user:loginReducer}),//applyMiddleware(thunk),exportdefaultstore;4.importimportReact,{Component}from"react";import{Redirect}from"react-router-dom";import{connect}from"react-exportdefaultstate=>({loading:err:{/*login:()=>type:}),/*login:()=>dispatch{dispatch({type:"requestLogin"});setTimeout(()=>{type:},},login:name=>({type:"login",nameclassLoginPageextends{constructor(props){this.state={name:}setName=event{name:render()const{isLogin,loading,err,location,}=if(isLogin){const{redirect="/"}=location.statereturn<Redirectto={redirect}}const{name}=this.state;return({err&&<inputvalue={name}<buttononClick={()=>{loading"登錄中"登錄}why開(kāi)箱即用,內(nèi)置react、react-router等式完善的插件體系,覆蓋從源碼到構(gòu)建產(chǎn)物的每個(gè)生命周期高性能,通過(guò)插件支持PWA、以路由為單元的codesplitting開(kāi)發(fā)啟動(dòng)快,支持一鍵開(kāi)啟dll和hard-source-wck-plugin等IE9umi-plugin-與dva數(shù)據(jù)流的深入融合,支持duckdirectory、model的自動(dòng)加載、codesplitting等等srccomponents組件con?g配置mock數(shù)據(jù)模擬環(huán)境要求:node版本創(chuàng)建:yarncreateumi安裝依賴:yarn或者npm啟動(dòng):yarnstart或者umi其他例子:如umi- umiumigpageumiumigpagechannel/index--importrouterfromumi/routerumiumi about:理解入,側(cè)重于展示型交互性邏輯。ModelPageDVAredux、redux-sagareact-router的輕量級(jí)前端框statee?ectsubscriptionsrouter namespace:model名空間,只能用字符串。一個(gè)大型應(yīng)用可能包含多個(gè)model,通過(guò)namespace區(qū)分 reducers:用于修改state,由 是一個(gè)純函數(shù),它接受當(dāng)前的state及一個(gè)action對(duì)象。action對(duì)象里面可以包含數(shù)據(jù)體(payload)作為入?yún)?,需要返回一個(gè)新的state。 務(wù)邏輯,也是由action觸發(fā)。但是,它不可以修改state,要通過(guò)觸發(fā)action調(diào)用reducer實(shí)現(xiàn)對(duì)state的間接操 action:是reducers及e?ects的觸發(fā)?,一般是一個(gè)對(duì)象,形如type:'add',payloadtodo,通過(guò)type屬性可以匹配到具體某個(gè)reducer或者e?ect,payload屬性則是數(shù)據(jù)體,用于傳送給reducer或e?ect。創(chuàng)建頁(yè)面goods.jsumigpagechannel/indeximportimportReact,{Component}from'react';importstylesfrom'./index.less';import{PageHeaderWrapper}from'@ant-{;importconnect}fromCard,Form,Input,Button,Table}constcolumns={title: key:'name',{title:'年齡',key:'age',{title:'住址',key:'city',classChannelextends{componentDidMount(){}search=()=>const{getFieldValue}=ps.form;constname=getFieldValue('name');render()const{form,data}=ps;const{getFieldDecorator}=form;return(<div<Card<Buttontype="primary"<TabledataSource={data}{columns}rowKey={record=>record.id}}}exportdefaultconnect(({channel})=>...channel}),{getChannelData:()=>({type:'channel/getChannelData'}),getChannelDataBySearch:search=>({type:importimport{getChannelData,getChannelDataBySearch}from'@/services/channel.js';constmodel{namespace:'channel',state:{data:effects:*getChannelData({payload},{call,put{constresponse=yieldcall(getChannelData,yieldpayload:response,})
*getChannelDataBySearch({payload},{call,constresponse=call(getChannelDataBySearch,payload);yieldpayload:response,reducers:channelData(state,{payload})return{...state,data:[...payload.data]exportexportdefaultimportimportrequestfrom'@/utils/request';exportasyncfunctiongetChannelData(params){returnrequest('/api/getChannelData',{method:'get',}exportasyncfunction{method:'post',data:params,} const
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025-2030年中國(guó)盆花行業(yè)運(yùn)行態(tài)勢(shì)及發(fā)展趨勢(shì)分析報(bào)告
- 2025-2030年中國(guó)電極箔產(chǎn)業(yè)發(fā)展趨勢(shì)規(guī)劃研究報(bào)告
- 2025山東省建筑安全員《B證》考試題庫(kù)
- 長(zhǎng)沙軌道交通職業(yè)學(xué)院《幼兒戲劇》2023-2024學(xué)年第二學(xué)期期末試卷
- 唐山工業(yè)職業(yè)技術(shù)學(xué)院《軟件工程原理與實(shí)踐》2023-2024學(xué)年第二學(xué)期期末試卷
- 遼寧何氏醫(yī)學(xué)院《運(yùn)動(dòng)選材學(xué)》2023-2024學(xué)年第二學(xué)期期末試卷
- 滁州城市職業(yè)學(xué)院《工程實(shí)訓(xùn)》2023-2024學(xué)年第二學(xué)期期末試卷
- 中國(guó)計(jì)量大學(xué)《文學(xué)批評(píng)學(xué)》2023-2024學(xué)年第二學(xué)期期末試卷
- 廣西演藝職業(yè)學(xué)院《食品營(yíng)養(yǎng)學(xué)實(shí)驗(yàn)》2023-2024學(xué)年第二學(xué)期期末試卷
- 西安信息職業(yè)大學(xué)《文獻(xiàn)檢索與科技論文寫(xiě)作》2023-2024學(xué)年第二學(xué)期期末試卷
- 幼兒園廚師廚房崗位管理培訓(xùn)教學(xué)課件(一)
- 采購(gòu)需求管理附件2采購(gòu)需求-PR-PO操作說(shuō)明
- 化工過(guò)程安全管理導(dǎo)則
- 人教版《道德與法治》四年級(jí)下冊(cè)教材簡(jiǎn)要分析課件
- 智慧水利建設(shè)頂層設(shè)計(jì)
- 數(shù)字示波器的工作原理及其應(yīng)用
- 應(yīng)聘登記表員工招聘登記表
- 肝內(nèi)膽管結(jié)石治療共識(shí) 課件
- 常見(jiàn)婚姻家庭糾紛及調(diào)解的技巧課件
- 新人教版高中數(shù)學(xué)必修二全冊(cè)教學(xué)課件ppt
- Python數(shù)據(jù)分析與應(yīng)用
評(píng)論
0/150
提交評(píng)論