Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
basic-uniapp-v3
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Basic
basic-uniapp-v3
Commits
ab79f9fc
提交
ab79f9fc
authored
3月 25, 2023
作者:
方治民
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 添加网络请求 inject 实现,允许动态修改请求配置
上级
d4e8f9ab
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
24 行增加
和
3 行删除
+24
-3
Axios.ts
src/utils/http/axios/Axios.ts
+8
-2
axiosTransform.ts
src/utils/http/axios/axiosTransform.ts
+9
-0
index.ts
src/utils/http/axios/index.ts
+7
-1
没有找到文件。
src/utils/http/axios/Axios.ts
浏览文件 @
ab79f9fc
...
...
@@ -259,12 +259,18 @@ export class VAxios {
const
{
requestOptions
}
=
this
.
options
cons
t
opt
:
RequestOptions
=
Object
.
assign
({},
requestOptions
,
options
)
le
t
opt
:
RequestOptions
=
Object
.
assign
({},
requestOptions
,
options
)
const
{
beforeRequestHook
,
requestCatchHook
,
transformRequestHook
}
=
transform
||
{}
const
{
beforeRequestHook
,
requestCatchHook
,
transformRequestHook
,
inject
}
=
transform
||
{}
if
(
inject
&&
isFunction
(
inject
))
{
const
result
=
inject
(
conf
,
opt
)
conf
=
result
.
config
opt
=
result
.
options
}
if
(
beforeRequestHook
&&
isFunction
(
beforeRequestHook
))
{
conf
=
beforeRequestHook
(
conf
,
opt
)
}
conf
.
requestOptions
=
opt
conf
=
this
.
supportFormData
(
conf
)
...
...
src/utils/http/axios/axiosTransform.ts
浏览文件 @
ab79f9fc
...
...
@@ -12,6 +12,15 @@ export interface CreateAxiosOptions extends AxiosRequestConfig {
export
abstract
class
AxiosTransform
{
/**
* 注入自定义配置,在请求方法调用时
* 允许动态修改本次请求的 config 和 options
*/
inject
?:
(
config
:
AxiosRequestConfig
,
options
:
RequestOptions
,
)
=>
{
config
:
AxiosRequestConfig
;
options
:
RequestOptions
}
/**
* @description: Process configuration before request
* @description: Process configuration before request
*/
...
...
src/utils/http/axios/index.ts
浏览文件 @
ab79f9fc
...
...
@@ -267,8 +267,14 @@ export const defHttp = createAxios({
// other api url
// export const otherHttp = createAxios({
// transform: {
// inject: (config: AxiosRequestConfig<any>, options: http.RequestOptions) => {
// // TODO: 根据实际项目配置
// return { config, options }
// },
// },
// requestOptions: {
// apiUrl: 'xxx',
// urlPrefix: 'xxx',
// },
// })
;
// })
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论