按照umi + dva 发现不触发reducers的问题

栏目: IOS · 发布时间: 6年前

内容简介:我的 login这样写死了user: 1, 但是user的状态还是不变,触发login后user永远是初始状态???tasks 组件内获取到也是null, 无法通过put改变状态啊求指点!

我的 login这样写死了user: 1, 但是user的状态还是不变,触发login后user永远是初始状态???

tasks 组件内获取到也是null, 无法通过put改变状态啊

求指点!

export default {
  namespace: 'app',
  state: {
    user: null,
    locationPathname: '',
    locationQuery: {},
  },

  subscriptions: {
    setupHistory ({ dispatch, history }) {
      history.listen((location) => 
        dispatch({
          type: 'updateState',
          payload: {
            locationPathname: location.pathname,
            locationQuery: location.query,
          },
        })
      )
    },
    setup ({ dispatch }) {
      dispatch({ type: 'doLogin', payload: {  } })
    },
  },

  effects: {
    * doLogin ({ payload }, { call, put, select }) {
      yield put({ type: 'login', payload: {user: 1}})
      let { user } = yield select(_ => _.app)
      // console.log(user) null
      yield put(routerRedux.push({
        pathname: '/tasks',
      }))
    },

    * loginOut ({ payload }, { call, put, select }) {
      yield put({ type: 'updateState', payload: {
        user: null,
      }})
      yield put(routerRedux.push({
        pathname: '/login',
      }))
    },
  },

  reducers: {
    updateState (state, { payload }) {
      return {
        ...state,
        ...payload,
      }
    },
    login (state, { payload }) {
      return {
        ...state,
        user: 1,
      }
    },
  },
}

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

An Introduction to Probability Theory and Its Applications

An Introduction to Probability Theory and Its Applications

William Feller / Wiley / 1991-1-1 / USD 120.00

Major changes in this edition include the substitution of probabilistic arguments for combinatorial artifices, and the addition of new sections on branching processes, Markov chains, and the De Moivre......一起来看看 《An Introduction to Probability Theory and Its Applications》 这本书的介绍吧!

html转js在线工具
html转js在线工具

html转js在线工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试