Dva: 如何在 request.js 使用 dispatch

Created on 17 Sep 2017  ·  8Comments  ·  Source: dvajs/dva

因为我要在request.js 针对后端返回的code 进行全局处理,但是如果用 history里面的 createBroswer.push 虽然 浏览器地址栏变了,但是视图没有变化,在routes中使用dispatch(routerRedux.push(url))是可以正常的

dva 2.0

Most helpful comment

ant-pro有统一处理

index.js
app.start('#root')
export default app._store;

request.js
import store from '@/index'
const { dispatch } = store;

All 8 comments

目前的解决方案我是用的 location.href = url,但是感觉不好,有没有更简洁的方法

request 是在 effect 里发起的,effect 里拿到 request 的结果,put action 跳转。

同问,如我要再 request.js的返回里做一个统一的处理。 因为所有的请求都访问到这里。再这里做很方便

同问,如我要再 request.js的返回里做一个统一的处理。 因为所有的请求都访问到这里。再这里做很方便
+1

request里面throw dva onError 里处理 可以dispatch

我把它throw到index里面去了,在 const app = dva({}) 里面做的处理,但总感觉不太对。

统一处理401等错误,然后跳转到相应页面,在vue下就很简单,直接在request里用store.dispatch就好了。React下的东西整的太复杂了。

ant-pro有统一处理

index.js
app.start('#root')
export default app._store;

request.js
import store from '@/index'
const { dispatch } = store;

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MiaoXingGua picture MiaoXingGua  ·  3Comments

itiwll picture itiwll  ·  4Comments

mclouvem picture mclouvem  ·  4Comments

wm3445 picture wm3445  ·  3Comments

pengfeiWang picture pengfeiWang  ·  3Comments