更改axios的默认基本URL [英] Change the default base url for axios
本文介绍了更改axios的默认基本URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经这样配置了我的axios
I have configured my axios like this
const axiosConfig = {
baseURL: 'http://127.0.0.1:8000/api',
timeout: 30000,
};
Vue.prototype.$axios = axios.create(axiosConfig)
在我的组件内部,我打电话给
Inside my component i make a call as
this.$axios.get('items').then()..
现在上述方法可行,但我想更改 baseURL
而不影响全局基本URL,以便在我的组件中无需API端点即可直接使用
Now the above works but i would like to change the baseURL
without affecting the global base URL so that in my component i can simply use without API endpoint so
我尝试过
this.$axios.baseURL = "http://127.0.0.1:8000";
this.$axios.get().. //this is still in api endpoint
我该怎么办?
推荐答案
代替
this.$axios.get('items')
使用
this.$axios({ url: 'items', baseURL: 'http://new-url.com' })
如果您不通过方法:'XXX'
,则默认情况下,它将通过 get
方法发送.
If you don't pass method: 'XXX'
then by default, it will send via get
method.
请求配置: https://github.com/axios/axios#request-config
这篇关于更改axios的默认基本URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文