Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useRequest 和 useRequestCallback 不支持请求的时候,传递一些axios的配置项吗 #113

Open
ghost opened this issue May 19, 2022 · 2 comments

Comments

@ghost
Copy link

ghost commented May 19, 2022

比如有一个请求
getData('post', {
params: {} // 请求地址?后面拼接的参数
data: {} // body中的参数
})
这两中参数都要传过去,useRequest 和 useRequestCallback 就没办法区别两种类型的参数,会全部拼接到?后面

@otakustay
Copy link
Member

回晚了。useRequest虽然名字上这么叫,但它本质是对异步的封闭,和axios或fetch是完全没关系的

useRequest的逻辑就是,你有一个异步的函数,我负责处理它的调用过程。

对于你的需求,应该这么做:

const getMyData = ({params, data}) => {
  return getData('post', params, data);
};

useRequest(getMyData, {params: {}, data: {}});

自己再封一层函数就能处理这种情况。useRequest默认既不会拼到?后面,也不会放到body里面,因为它根本不和HTTP请求有关

@ghost
Copy link
Author

ghost commented Jun 2, 2022

感谢回复,我知道该怎么做了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant