不同的接口需要不同的接口全路径,当想要请求其他后台地址时候,需要增加新的域名实例

env.development不变,不在里面修改

src/utils/http/axios/index.ts文件

​export const defHttp = createAxios();//原来的defHttp,代码原来就有的,


// 在代码最后面新增域名实例othersHttp

export const othersHttp = createAxios({

requestOptions: {

apiUrl: 'https://xxx.xxx.com/api', // 新的域名

},

});

​

api中使用新增的域名实例

import { defHttp, othersHttp } from '/@/utils/http/axios';//保持统一


enum Api {
    getlist='/getlist',
}

export function getlist() {
  return othersHttp.get({ url: Api.getlist });  //此处修改,想用哪个用哪个
}

完成✅

Logo

Agent 垂直技术社区,欢迎活跃、内容共建。

更多推荐