React 中的model的effects获取state中某个值

export default {
  namespace: 'tdCall',
  state: {
    mToken: null,
    device: null,
  },

  effects: {
    *getDeviceCall({ payload }, { select, call, put }) {
      const { mToken } = yield select(_ => _.tdCall);// 获取state中某个值
      const response = yield call(getDeviceCall, payload, mToken);
      if (response) {
        const { result } = response;
        if (result) {
          yield put({
            type: 'setDeviceCall',
            payload: result,
          });
        }
      }
    },
  },

  reducers: {
    setDeviceCall(state, action) {
      return {
        ...state,
        device: action.payload,
      };
    },
    setMToken(state, action) {
      return {
        ...state,
        mToken: action.payload,
      };
    },
  },
};

 

posted @ 2026-05-27 16:50  94cool  阅读(9)  评论(0)    收藏  举报