File tree 5 files changed +71
-25
lines changed
5 files changed +71
-25
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,24 @@ parameterNames() {
65
65
}
66
66
```
67
67
68
+ ### ` formData `
69
+ - Returns: ` object `
70
+
71
+ This method can be overridden in the model to configure ` object-to-formdata ` .
72
+
73
+ See [ object-to-formdata] ( https://github.com/therealparmesh/object-to-formdata#usage )
74
+
75
+ ``` js
76
+ formData () {
77
+ return {
78
+ indices: false ,
79
+ nullsAsUndefineds: false ,
80
+ booleansAsIntegers: false ,
81
+ allowEmptyArrays: false ,
82
+ }
83
+ }
84
+ ```
85
+
68
86
#### ` include `
69
87
- Default: ` include `
70
88
- Returns: ` string `
Original file line number Diff line number Diff line change @@ -193,3 +193,47 @@ export default class Model extends BaseModel {
193
193
}
194
194
}
195
195
```
196
+
197
+ ## Configuring FormData
198
+
199
+ See the [ API reference] ( /api/model-options#formdata ) and [ object-to-formdata] ( https://github.com/therealparmesh/object-to-formdata#usage )
200
+
201
+ When uploading files, the data of our request will be automatically converted to ` FormData ` using ` object-to-formdata ` .
202
+
203
+ If needed, we can easily configure the options by overriding the ` formData ` method.
204
+
205
+ We can globally configure this in the [ Base Model] ( /configuration#creating-a-base-model ) :
206
+
207
+ ``` js{}[~/models/Model.js]
208
+ import { Model as BaseModel } from 'vue-api-query'
209
+
210
+ export default class Model extends BaseModel {
211
+
212
+ // Define a base url for a REST API
213
+ baseURL() {
214
+ return 'http://my-api.com'
215
+ }
216
+
217
+ // Implement a default request method
218
+ request(config) {
219
+ return this.$http.request(config)
220
+ }
221
+
222
+ // Override default query parameter names
223
+ parameterNames() {
224
+ const defaultParams = super.parameterNames()
225
+ const customParams = {
226
+ include: 'include_custom'
227
+ }
228
+
229
+ return { ...defaultParams, ...customParams }
230
+ }
231
+
232
+ // Configure object-to-formadata
233
+ formData() {
234
+ return {
235
+ indices: true
236
+ }
237
+ }
238
+ }
239
+ ```
Original file line number Diff line number Diff line change 63
63
"dependencies" : {
64
64
"dotprop" : " ^1.2.0" ,
65
65
"dset" : " ^2.0.1" ,
66
- "object-to-formdata" : " ^4.1.0"
66
+ "object-to-formdata" : " ^4.1.0" ,
67
+ "qs" : " ^6.9.4"
67
68
}
68
69
}
Original file line number Diff line number Diff line change @@ -42,30 +42,8 @@ export default class Model extends StaticModel {
42
42
return this
43
43
}
44
44
45
- formData ( options = { } ) {
46
- const defaultOptions = {
47
- /**
48
- * Include array indices in FormData keys
49
- */
50
- indices : false ,
51
-
52
- /**
53
- * Treat null values like undefined values and ignore them
54
- */
55
- nullsAsUndefineds : false ,
56
-
57
- /**
58
- * Convert true or false to 1 or 0 respectively
59
- */
60
- booleansAsIntegers : false ,
61
-
62
- /**
63
- * Store arrays even if they're empty
64
- */
65
- allowEmptyArrays : false ,
66
- }
67
-
68
- return { ...defaultOptions , ...options }
45
+ formData ( ) {
46
+ return { }
69
47
}
70
48
71
49
resource ( ) {
Original file line number Diff line number Diff line change @@ -6284,6 +6284,11 @@ qrcode-terminal@^0.12.0:
6284
6284
resolved "https://registry.yarnpkg.com/qrcode-terminal/-/qrcode-terminal-0.12.0.tgz#bb5b699ef7f9f0505092a3748be4464fe71b5819"
6285
6285
integrity sha512-EXtzRZmC+YGmGlDFbXKxQiMZNwCLEO6BANKXG4iCtSIM0yqc/pappSx3RIKr4r0uh5JsBckOXeKrB3Iz7mdQpQ==
6286
6286
6287
+ qs@^6.9.4 :
6288
+ version "6.9.4"
6289
+ resolved "https://registry.yarnpkg.com/qs/-/qs-6.9.4.tgz#9090b290d1f91728d3c22e54843ca44aea5ab687"
6290
+ integrity sha512-A1kFqHekCTM7cz0udomYUoYNWjBebHm/5wzU/XqrBRBNWectVH0QIiN+NEcZ0Dte5hvzHwbr8+XQmguPhJ6WdQ==
6291
+
6287
6292
qs@~6.5.2 :
6288
6293
version "6.5.2"
6289
6294
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36"
You can’t perform that action at this time.
0 commit comments