dva icon indicating copy to clipboard operation
dva copied to clipboard

如何在 request.js 使用 dispatch

Open smithyj opened this issue 9 years ago • 8 comments

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

dva 2.0

smithyj avatar Sep 17 '17 08:09 smithyj

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

smithyj avatar Sep 17 '17 08:09 smithyj

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

sorrycc avatar Sep 17 '17 11:09 sorrycc

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

codercatmomi avatar Oct 09 '17 14:10 codercatmomi

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

Ashley2014 avatar Nov 08 '17 09:11 Ashley2014

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

smithyj avatar Nov 16 '17 01:11 smithyj

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

tworry avatar Dec 26 '17 07:12 tworry

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

hezhijun avatar Jan 06 '18 15:01 hezhijun

ant-pro有统一处理

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

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

felix9ia avatar Jun 27 '18 05:06 felix9ia