Skip to content

Commit 40a9d75

Browse files
committed
chore: 🔥 use inject and change how axios work on method
1 parent ea0332f commit 40a9d75

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

nuxt/templates/plugin.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import VueApiQueries, { Validator } from 'vue-api-queries'
44
const options = <%= serialize(options) %> || {}
55
const { errorProperty, parsedQs } = options
66

7-
export default function (ctx) {
8-
Vue.use(VueApiQueries, { errorProperty, axios: ctx.$axios, parsedQs })
9-
ctx.$errors = Validator
7+
export default function ({ $axios }, inject) {
8+
Vue.use(VueApiQueries, { errorProperty, axios: $axios, parsedQs })
9+
inject('errors', Validator)
1010
}

src/core/BaseProxy.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {
1+
import type {
22
AxiosError,
33
AxiosInstance,
44
AxiosResponse,
@@ -201,12 +201,11 @@ class BaseProxy {
201201
? `/${this.endpoint}/${parameter}`
202202
: `/${this.endpoint}`
203203
const endpoint = this.__getParameterString(removeDoubleSlash(url))
204-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
205-
// @ts-ignore
206-
this.$http[method](endpoint, data, config)
204+
const axiosConfig: AxiosRequestConfig = { data, method }
205+
this.$http(endpoint, Object.assign({}, config, axiosConfig))
207206
.then((response: AxiosResponse) => {
208207
this.onSuccess()
209-
const { data } = response
208+
const { data } = response || {}
210209
resolve(data)
211210
})
212211
.catch((error: AxiosError) => {
@@ -237,7 +236,7 @@ class BaseProxy {
237236
return `${url}${query}`
238237
}
239238

240-
private static __validateRequestType(requestType: Method): string {
239+
private static __validateRequestType(requestType: Method): Method {
241240
const requestTypes: string[] = [
242241
'get',
243242
'delete',
@@ -252,7 +251,7 @@ class BaseProxy {
252251
`must be one of: \`${requestTypes.join('`, `')}\`.`,
253252
)
254253
}
255-
return requestType.toLowerCase()
254+
return requestType
256255
}
257256

258257
/**

src/core/Validator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Validator {
5454
value = obj[field]
5555
}
5656
if (isArray(value)) {
57-
return value[0]
57+
value = value[0]
5858
}
5959
return value
6060
}

0 commit comments

Comments
 (0)