File tree 2 files changed +28
-0
lines changed
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,31 @@ let data = (await $axios.get('...')).data
36
36
let data = await $axios .$get (' ...' )
37
37
```
38
38
39
+ ### ` setBaseURL(baseURL) `
40
+
41
+ Axios instance has an additional helper to easily change baseURL.
42
+
43
+ Use this when you need a dynamic runtime url. Otherwise use config and environment variables.
44
+
45
+ Parameters:
46
+
47
+ * ** baseURL** : Base URL which is used and prepended to make requests in server side.
48
+
49
+ ``` js
50
+ // Set baseURL (both client and server)
51
+ this .$axios .setBaseURL (' http://api.example.com' )
52
+
53
+ // Change URL only for client
54
+ if (process .client ) {
55
+ this .$axios .setBaseURL (' http://api.example.com' )
56
+ }
57
+
58
+ // Change URL only for server
59
+ if (process .server ) {
60
+ this .$axios .setBaseURL (' http://api.example.com' )
61
+ }
62
+ ```
63
+
39
64
### ` setHeader(name, value, scopes='common') `
40
65
41
66
Axios instance has a helper to easily set any header.
Original file line number Diff line number Diff line change @@ -3,6 +3,9 @@ import Axios from 'axios'
3
3
4
4
// Axios.prototype cannot be modified
5
5
const axiosExtra = {
6
+ setBaseURL ( baseURL ) {
7
+ this . defaults . baseURL = baseURL
8
+ } ,
6
9
setHeader ( name , value , scopes = 'common' ) {
7
10
for ( let scope of Array . isArray ( scopes ) ? scopes : [ scopes ] ) {
8
11
if ( ! value ) {
You can’t perform that action at this time.
0 commit comments