@@ -54,9 +54,10 @@ import { useRequest, useResource } from "@axios-use/vue";
5454
5555### Options (optional)
5656
57- | config | type | default | explain |
58- | -------- | ------ | ------- | ------------------------------------------------------------- |
59- | instance | object | ` axios ` | Axios instance. You can pass your axios with a custom config. |
57+ | config | type | default | explain |
58+ | --------------- | -------- | --------------- | --------------------------------------------------------------------------------------------------------------------- |
59+ | instance | object | ` axios ` | Axios instance. You can pass your axios with a custom config. |
60+ | getResponseItem | function | ` (r) => r.data ` | custom ` data ` value. The default value is response[ 'data'] . [ PR #1 ] ( https://github.com/axios-use/axios-use-vue/pull/1 ) |
6061
6162``` ts
6263import axios from " axios" ;
@@ -83,12 +84,13 @@ Vue.use(AxiosUseVue, { instance: axiosInstance });
8384
8485### useRequest
8586
86- | option | type | explain |
87- | ------------------- | --------------- | ------------------------------------------------ |
88- | fn | function | get AxiosRequestConfig function |
89- | options.onCompleted | function | This function is passed the query's result data. |
90- | options.onError | function | This function is passed an ` RequestError ` object |
91- | options.instance | ` AxiosInstance ` | Customize the Axios instance of the current item |
87+ | option | type | explain |
88+ | ----------------------- | --------------- | ------------------------------------------------ |
89+ | fn | function | get AxiosRequestConfig function |
90+ | options.onCompleted | function | This function is passed the query's result data. |
91+ | options.onError | function | This function is passed an ` RequestError ` object |
92+ | options.instance | ` AxiosInstance ` | Customize the Axios instance of the current item |
93+ | options.getResponseItem | function | custom returns the value of ` data ` (index 0). |
9294
9395``` ts
9496// js
@@ -136,15 +138,16 @@ const [createRequest, { hasPending, cancel }] = useRequest(
136138
137139### useResource
138140
139- | option | type | explain |
140- | -------------------- | --------------- | ------------------------------------------------------------------- |
141- | fn | function | get AxiosRequestConfig function |
142- | parameters | array \| false | ` fn ` function parameters. effect dependency list |
143- | options.filter | function | Request filter. if return a falsy value, will not start the request |
144- | options.defaultState | object | Initialize the state value. ` {data, response, error, isLoading} ` |
145- | options.onCompleted | function | This function is passed the query's result data. |
146- | options.onError | function | This function is passed an ` RequestError ` object |
147- | options.instance | ` AxiosInstance ` | Customize the Axios instance of the current item |
141+ | option | type | explain |
142+ | ----------------------- | --------------- | ------------------------------------------------------------------- |
143+ | fn | function | get AxiosRequestConfig function |
144+ | parameters | array \| false | ` fn ` function parameters. effect dependency list |
145+ | options.filter | function | Request filter. if return a falsy value, will not start the request |
146+ | options.defaultState | object | Initialize the state value. ` {data, response, error, isLoading} ` |
147+ | options.onCompleted | function | This function is passed the query's result data. |
148+ | options.onError | function | This function is passed an ` RequestError ` object |
149+ | options.instance | ` AxiosInstance ` | Customize the Axios instance of the current item |
150+ | options.getResponseItem | function | custom returns the value of ` data ` (index 0). |
148151
149152``` ts
150153// js
@@ -302,7 +305,8 @@ unref(reqState).data;
302305const [reqState] = useResource (() => _request <MyWrapper <DataType >>({ url: ` /users ` }));
303306// MyWrapper<DataType>
304307unref (reqState ).response ;
305- // MyWrapper<DataType>["data"]. maybe `undefined` type
308+ // MyWrapper<DataType>["data"]. maybe `undefined` type.
309+ // You can use `getResponseItem` to customize the value of `data`
306310unref (reqState ).data ;
307311```
308312
0 commit comments