admin管理员组

文章数量:1404563

I'm trying to get the baseURL from customApi.js axios that is created using export default axios.create()configuration.

customApi.js file

import axios from 'axios';

export default axios.create({
    baseURL: 'http://123.123.123.123:5000'
});

I tried the following, but it console logs undefined.

import api from 'customApi.js';

console.log(api.baseURL);

What is the correct way to get the base url in a custom configured axios?

I'm trying to get the baseURL from customApi.js axios that is created using export default axios.create()configuration.

customApi.js file

import axios from 'axios';

export default axios.create({
    baseURL: 'http://123.123.123.123:5000'
});

I tried the following, but it console logs undefined.

import api from 'customApi.js';

console.log(api.baseURL);

What is the correct way to get the base url in a custom configured axios?

Share Improve this question asked May 28, 2020 at 11:51 kaizenkaizen 1,6384 gold badges31 silver badges53 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

Here is how I found it.

const x = axios.create({
    baseURL: 'http://123.123.123.123:5000'
});

// for (let o in x) console.log(o,x[o])

console.log(x.defaults.baseURL)
<script src="https://cdnjs.cloudflare./ajax/libs/axios/0.19.2/axios.min.js"></script>

本文标签: javascriptHow to Get the BaseURL from axioscreate(baseURL)Stack Overflow