dva-vue icon indicating copy to clipboard operation
dva-vue copied to clipboard

dispatch 其他model报错 demo也是报错的

Open michael712520 opened this issue 6 years ago • 2 comments

Profile.vue down () { this.dispatch({type: 'index/getUser', payload: 'aa'}).then(() => console.log('done')) }

michael712520 avatar Sep 05 '18 00:09 michael712520

@michael712520 不好意思,因为只有当effect 里面的方法才有then

Jetsly avatar Sep 19 '18 07:09 Jetsly

app.model({
  namespace: "count",
  state: 0,
  reducers: {
    add(state, { payload }) {
      return state + payload || 1;
    },
    minus(state, { payload }) {
      return state - payload || 1;
    }
  },
  effects: {
    *asyncAdd(_, { call, put }) {
      // as some fetch action
      yield delay(1000);
      yield put({ type: "add", payload: 1 });
    }
  }
})

---

有then

this.dispatch({type: 'index/asyncAdd', payload: 'aa'}) 

没有then

this.dispatch({type: 'index/add', payload: 'aa'}) 

Jetsly avatar Sep 19 '18 07:09 Jetsly