1、默认axios不变
axios.defaults.baseURL = 'http://www.ipkd.cn'; //填写域名
2、创建一个新的变量代替axios
const loginApi = axios.create({
baseURL: 'http://www.baidu.com',
});
3、把所有用的方法都用loginApi改一遍
loginApi.interceptors.request.use(config => {
config.headers["Content-Type"] = 'application/x-www-form-urlencoded'
})
//响应拦截器即异常处理
loginApi.interceptors.response.use(response => {
return response
//请求失败
}, err => {
Message({
type: "error",
message: err.response.data.Message
});
return Promise.resolve(err.response)
})
//封装get/post等方法也需要修改
export function get(url, params = {}) {
}
//其它的调用就不说了
以上是编程学习网小编为您介绍的“axios.defaults.baseURL如何实现一个页面调用多个bas”的全面内容,想了解更多关于 vuejs 内容,请继续关注编程基础学习网。
沃梦达教程
本文标题为:axios.defaults.baseURL如何实现一个页面调用多个bas


猜你喜欢
- Vue:三种情况下的生命周期执行顺序 2023-10-08
- vue-cli · Failed to download repo vuejs-templates/webpack: connect ECONNREF 2023-10-08
- 浅谈async、defer以普通script加载的区别 2023-07-09
- 用纯CSS实现禁止鼠标点击事件示例代码 2024-01-05
- vue cli3 + ts 打包之后,不显示页面 2023-10-08
- js设置cookie过期及清除浏览器对应名称的cookie 2024-02-12
- Ajax返回数据之前的loading等待效果 2023-02-14
- CSS让子容器超出父元素(子容器悬浮在父容器效果) 2023-12-15
- 网页变灰配合全国哀悼日的css代码 20100421 2024-02-21
- 用一个DIV画图通过background-image叠加实现 2024-02-25