dva dispatch

2020-01-08  本文已影响0人  第2世界

jsx中事件处理中有dispatch

dispatch({type: 'count/add'}) //这里的count是model的命名空间,"/"后面的表示model中effects的异步方法名

model:

{
  namespace: 'count', //dispatch中引用的命名空间
  state: 0,
  reducers: {
    add(state) { return state + 1 },
  },
  effects: {
    *addAfter1Second(action, { call, put }) {
      yield call(delay, 1000);
      yield put({ type: 'add' });
    },
  },
}
上一篇下一篇

猜你喜欢

热点阅读