@@ -10,9 +10,9 @@ function useRequestImplement<TData, TParams extends any[]>(
10
10
options : UseRequestOptions < TData , TParams , any > = { } ,
11
11
plugins : UseRequestPlugin < TData , TParams > [ ] = [ ] ,
12
12
) {
13
- // 全局注入的配置
13
+ // global option
14
14
const USEREQUEST_GLOBAL_OPTIONS = inject ( USEREQUEST_GLOBAL_OPTIONS_PROVIDE_KEY )
15
- // 读取配置
15
+ // read option
16
16
const { initialData = undefined , manual = false , ready = true , ...rest } = merge (
17
17
USEREQUEST_GLOBAL_OPTIONS ,
18
18
options ?? { } ,
@@ -24,10 +24,10 @@ function useRequestImplement<TData, TParams extends any[]>(
24
24
...rest ,
25
25
}
26
26
27
- // 定义一个serviceRef
27
+ // serviceRef store service
28
28
const serviceRef = ref ( service )
29
29
30
- // 存储state的响应式对象
30
+ // reactive
31
31
const state = reactive < {
32
32
data ?: TData
33
33
loading : boolean
@@ -52,7 +52,7 @@ function useRequestImplement<TData, TParams extends any[]>(
52
52
}
53
53
54
54
const initState = plugins . map ( p => p ?. onInit ?.( fetchOptions ) ) . filter ( Boolean )
55
- // fetch的实例化
55
+ // Fetch Instance
56
56
const fetchInstance = new Fetch < TData , TParams > (
57
57
serviceRef ,
58
58
fetchOptions ,
@@ -62,20 +62,20 @@ function useRequestImplement<TData, TParams extends any[]>(
62
62
63
63
fetchInstance . options = fetchOptions
64
64
65
- // 运行插件
65
+ // run plugins
66
66
fetchInstance . pluginImpls = plugins . map ( p => {
67
67
return p ( fetchInstance , fetchOptions )
68
68
} )
69
69
70
- // manual控制是否自动发送请求
70
+ // manual
71
71
onMounted ( ( ) => {
72
72
if ( ! manual ) {
73
73
const params = fetchInstance . state . params || options . defaultParams || [ ]
74
74
if ( unref ( ready ) ) fetchInstance . run ( ...( params as TParams ) )
75
75
}
76
76
} )
77
77
78
- // 组件卸载的时候取消请求
78
+ // onUnmounted cancel request
79
79
onUnmounted ( ( ) => {
80
80
fetchInstance . cancel ( )
81
81
} )
0 commit comments