Skip to content

Commit ada0a0f

Browse files
committed
docs(configuration): add section "Configuring FormData"
1 parent 05ef817 commit ada0a0f

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

Diff for: docs/content/en/configuration.md

+44
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,47 @@ export default class Model extends BaseModel {
193193
}
194194
}
195195
```
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+
```

0 commit comments

Comments
 (0)