Skip to content

Middleware是否可以支持网络请求? #12

Closed Answered by junerver
danatechgithub4 asked this question in Q&A
Discussion options

You must be logged in to vote

TodosListContainer()例子来说,我删除一个Todo,调用网络接口成功后,网络接口只会返回给成功或者失败,成功后,我再调用dispatch(DelTodo(item.id))。直接useRequest怎么做?

失败后弹个弹窗提示一下。

你想表达的是不是:

  • 接口1 :列表接口
  • 接口2:del接口

期望:

  1. 进入页面请求接口1,获取列表渲染
  2. 点击del、发起请求接口2
  3. 根据 步骤2,提示 or 更新列表

这个需求完全可以通过 useRequest 达成
将这两个接口分别使用useRequest创建,然后解构出接口1的状态、refresh函数;
接口2设置为手动出发,解构出 run 函数,同时注册生命周期函数:onSuccess 时调用1的 refresh、onError 时回调 toast

Replies: 6 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@danatechgithub4
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@danatechgithub4
Comment options

Comment options

You must be logged in to vote
1 reply
@danatechgithub4
Comment options

Answer selected by junerver
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants