我已经像这样配置了我的 axios
const axiosConfig = {
baseURL: 'http://127.0.0.1:8000/api',
timeout: 30000,
};
Vue.prototype.$axios = axios.create(axiosConfig)
在我的组件中,我拨打电话
this.$axios.get('items').then()..
现在上述工作,但我想更改 baseURL
而不影响全局基本 URL,以便在我的组件中我可以在没有 API 端点的情况下简单地使用它,所以
我试过了
this.$axios.baseURL = "http://127.0.0.1:8000";
this.$axios.get().. //this is still in api endpoint
我该怎么做?
原文由 Geoff 发布,翻译遵循 CC BY-SA 4.0 许可协议
代替
利用
如果你不通过
method: 'XXX'
那么默认情况下,它将通过get
方法发送。请求配置: https ://github.com/axios/axios#request-config