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

useReques hooks 管理 Promise Ajax 方法 #2539

Closed
luocong2016 opened this issue Feb 9, 2023 · 4 comments
Closed

useReques hooks 管理 Promise Ajax 方法 #2539

luocong2016 opened this issue Feb 9, 2023 · 4 comments
Labels
pr welcome Welcome developers to submit Pull Requests to the project

Comments

@luocong2016
Copy link

luocong2016 commented Feb 9, 2023

Subject of the feature

目前的 axios 封装了多个方法,使得 Ajax 变得复杂且不纯粹。

  1. 业务场景分析

很多中后台项目都是单点登录,且单点登录类型很多。

更特别是部署时,来回切换登录方式。

需要实现多个 axios 实例拦截,登录逻辑会变得非常复杂。

  1. 防抖,节流,可见重新,错误重试等功能

  2. 消息通知类型

  3. 监听功能,缓存,复用 hooks,手动触发等

若上述多个场景都封装到 axios 实例,这就会让 ajax 请求变得非常复杂,且错误后调试非常麻烦。
特别是在对接api接口的时候。

推荐下状态方法管理

我之前开发过 ahooks 的vue 版本的 request
useRequest

文档可以参考下:
https://ahooks.js.org/zh-CN/hooks/use-request/index

这个比目前封装的 axios 和 Form 下面很多API组件实用, 耦合度会降低很多

Problem

If the feature requests relates to a problem, please describe the problem you are trying to solve here.

Expected behaviour

希望改成可插拔型的 Promise 方法

1677226225984

Alternatives

What are the alternative solutions? Please describe what else you have considered?

@luocong2016 luocong2016 changed the title 为什么不考虑hook开发axios 为什么不考虑hook开发axios,我已经实现vue ahooks/useRequest Feb 24, 2023
@tttleon
Copy link

tttleon commented Feb 24, 2023

vue3 有vueuse,
useaxios
useasyncstate
axios和useRequest不是一个东西,axios是用来请求,useRequest是异步状态管理。

@luocong2016
Copy link
Author

luocong2016 commented Feb 24, 2023

vue3 有vueuse, useaxios useasyncstate axios和useRequest不是一个东西,axios是用来请求,useRequest是异步状态管理。

没说是一个东西。为此我改了 issues 防止到时候又出现理解偏差

说的是,这个东西(uesRequest)比现在这个项目封装axios实例适用。
比如:

  1. 错误重试
  2. 取消
  3. 防抖、节流
  4. 激活重新请求
    ...

axios 保留纯粹的 ajax 请求、响应的结构体,项目对API时利于排查问题。

@luocong2016 luocong2016 changed the title 为什么不考虑hook开发axios,我已经实现vue ahooks/useRequest useReques hooks 管理 Promise Ajax 方法 Feb 24, 2023
@wangjue666 wangjue666 added the pr welcome Welcome developers to submit Pull Requests to the project label Oct 9, 2023
@wangjue666
Copy link
Collaborator

resolve #3447

@likui628
Copy link
Collaborator

刚看到,我觉得还是作为npm包导入比较合适。
@luocong2016

@github-actions github-actions bot locked and limited conversation to collaborators Aug 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pr welcome Welcome developers to submit Pull Requests to the project
Projects
None yet
Development

No branches or pull requests

4 participants