第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

reducer有返回值,而且無(wú)論reducer的state怎么變化,但是打印的store時(shí)鐘為空的{}

reducer有返回值,而且無(wú)論reducer的state怎么變化,但是打印的store時(shí)鐘為空的{}

慕容3067478 2019-05-21 10:37:02
其實(shí)有好幾個(gè)問(wèn),卡了好久了不知道什么原因1.兩個(gè)reducer的state都有值的情況下store.subscribe(()=>{console.log("================監(jiān)聽(tīng)store變化:"+JSON.stringify(store));});打印的值一直是空的{}。2.點(diǎn)擊導(dǎo)航時(shí)候在Mount組件的時(shí)候去請(qǐng)求數(shù)據(jù),然后執(zhí)行store.dispatch(initUserAction(res)),初始化reducer的state,state有數(shù)據(jù),但是store.subscribe里面答應(yīng)的store一直是空的。這個(gè)是加載組件的時(shí)候初始化的代碼componentWillMount(){const{store}=this.context;fetch("http://localhost:3001/book").then(res=>res.json()).then(res=>{store.dispatch(initBookAction(res));});}這個(gè)是reducer的代碼constinitialState={data:[]};functionbookReducer(state=initialState,action){switch(action.type){case'INIT_BOOK_ACTION':console.log("=====初始化bookReducer:"+JSON.stringify(state));returnObject.assign({},state,{data:[...action.payload]})case'ADD_BOOK_ACTION':returnObject.assign({},state,{data:state.data.push(action.payload)})case'DELETE_BOOK_ACTION':returnObject.assign({},state,{data:state.data.filter(item=>item.id!=action.payload.id)})case'UPDATE_BOOK_ACTION':returnObject.assign({},state,{data:state.data.map(item=>{if(item.id==action.payload.id){returnObject.assign({},item,action.payload);}else{returnitem;}})})default:returnstate}}exportdefaultbookReducer;3.我加載的table的數(shù)據(jù)是mapStateToProps傳遞過(guò)來(lái)的數(shù)據(jù),既然store為空,為什么container組件中給mapStateToProps傳遞的state依然可以取到數(shù)據(jù)state.bookReducer.date,然后在table中展示出來(lái)數(shù)據(jù)呢?這個(gè)是rendertable的主要代碼render(){const{bookList,deleteBook}=this.props;//connect傳遞的propsconst{title,visible,confirmLoading}=this.state;//console.log("===================booklistprops:"+JSON.stringify(this.props));constcolumns=[{title:'圖書(shū)編號(hào)',dataIndex:'id'},{title:'名稱(chēng)',dataIndex:'name'},{title:'價(jià)格',dataIndex:'price'},{title:'借閱人編號(hào)',dataIndex:'owner_id'},{title:'操作',render:(text,record)=>(this.editHandle(record)}>編輯deleteBook(record)}>刪除)}];return(this.cancelHandle()}footer={null}>);}這個(gè)是創(chuàng)建container組件的代碼import{connect}from'react-redux';importBookListfrom'../components/BookList';import{deleteBookAction,addBookAction,updateBookAction}from'../actions/bookActions';constmapStateToProps=(state)=>{return{bookList:state.bookReducer.data};}constmapDispatchToProps=(dispatch)=>{return{deleteBook:(id)=>{dispatch(deleteBookAction(id))},addBook:(data)=>{dispatch(addBookAction(data))},editBook:(data)=>{dispatch(updateBookAction(data))}}}constBookListContainer=connect(mapStateToProps,mapDispatchToProps)(BookList);exportdefaultBookListContainer;代碼有點(diǎn)多我把github地址粘上來(lái),麻煩各位大神幫我看一下,謝謝~github地址:https://github.com/hesisi/rea...
查看完整描述

2 回答

?
有只小跳蛙

TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超8個(gè)贊

reducer沒(méi)有注冊(cè)到store
你要從“本源”上去看問(wèn)題,先看看你的entry.js
ReactDOM.render(
//routes
去看看store從哪里來(lái)的。最后追溯到一個(gè)整個(gè)應(yīng)用的reducer文件的匯總注冊(cè)文件reducer.js:
import{combineReducers}from"redux";
import{routerReducer}from"react-router-redux";
import*asyourComponentReducerfrom'./path/reducers.ts';
exportdefaultcombineReducers({
routing:routerReducer,
...yourComponentReducer,
});
                            
查看完整回答
反對(duì) 回復(fù) 2019-05-21
  • 2 回答
  • 0 關(guān)注
  • 561 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)