mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 10:37:07 +00:00
Add defaults to Vuex store api action.
It sends Content-Type: application/json by default and converts the body to string via JSON.stringify unless it's a string already.
This commit is contained in:
@@ -2,6 +2,17 @@
|
||||
async function api ({state, commit, dispatch}, [resource, init = {}]) {
|
||||
try {
|
||||
// this.loading = true;
|
||||
if (init && init.hasOwnProperty("body")) {
|
||||
if (!init.headers) {
|
||||
// As a convenience, we implicitly add the default content type
|
||||
init.headers = {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
}
|
||||
if (typeof init.body != "string") {
|
||||
init.body = JSON.stringify(init.body);
|
||||
}
|
||||
}
|
||||
const res = await fetch(`${state.apiUrl}${resource}`, init);
|
||||
if (res.ok) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user