File tree 1 file changed +27
-1
lines changed
1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,32 @@ export function getCSRFToken() {
18
18
return FALLBACK_TOKEN ;
19
19
}
20
20
21
+ /**
22
+ * This workaround addresses the limitation where ofetch does not handle array query params in PHP friendly way.
23
+ * Once this issue is resolved in ofetch, this function can be removed.
24
+ * Fo reference see:
25
+ * - https://github.com/unjs/ufo/issues/185
26
+ * - https://github.com/unjs/ufo/issues/208
27
+ * - https://github.com/unjs/ofetch/pull/440
28
+ *
29
+ */
30
+ function _formatQueryParams ( params ) {
31
+ if ( ! params ) {
32
+ return { }
33
+ }
34
+
35
+ const formatedParams = { } ;
36
+ Object . entries ( params ) . forEach ( ( [ key , value ] ) => {
37
+ if ( Array . isArray ( value ) ) {
38
+ formatedParams [ `${ key } []` ] = value ;
39
+ } else {
40
+ formatedParams [ key ] = value ;
41
+ }
42
+ } ) ;
43
+
44
+ return formatedParams ;
45
+ }
46
+
21
47
/**
22
48
*
23
49
* Composable for handling API requests
@@ -87,7 +113,7 @@ export function useFetch(url, options = {}) {
87
113
88
114
const opts = {
89
115
...ofetchOptions ,
90
- query : query . value ,
116
+ query : _formatQueryParams ( query . value ) ,
91
117
body : body . value ,
92
118
signal,
93
119
} ;
You can’t perform that action at this time.
0 commit comments