Dva: 怎么拿到整个state状态树啊?

Created on 17 Apr 2017  ·  2Comments  ·  Source: dvajs/dva

用redux工具查看每个路由下的状态,状态都是对应model里面的状态,如果我要用其他model里的状态,怎么获取啊

Most helpful comment

effects里面的Generator函数里面可以获得select函数,select函数能获取整个store里面的state。例子:

    *getUserList(action, { call, put, select }) {
      yield put({
        type: 'changeLoading',
        payload: true,
      });
      const query = yield select(state => state['UserManage/UserList'].query);
      console.log(query);
      const res = yield call(UserListService.getUserList, query);
      yield put({
        type: 'getUserListReducer',
        payload: res.data,
      });
    },

All 2 comments

effects里面的Generator函数里面可以获得select函数,select函数能获取整个store里面的state。例子:

    *getUserList(action, { call, put, select }) {
      yield put({
        type: 'changeLoading',
        payload: true,
      });
      const query = yield select(state => state['UserManage/UserList'].query);
      console.log(query);
      const res = yield call(UserListService.getUserList, query);
      yield put({
        type: 'getUserListReducer',
        payload: res.data,
      });
    },

太好了,就是她

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kpaxqin picture kpaxqin  ·  3Comments

sorrycc picture sorrycc  ·  3Comments

mclouvem picture mclouvem  ·  4Comments

MiaoXingGua picture MiaoXingGua  ·  3Comments

seamys picture seamys  ·  4Comments