Browse Source

调试跨域

pull/102/head
pengda 4 weeks ago
parent
commit
b0f1f2db2f
  1. 2
      .env.development
  2. 20
      src/utils/request.js
  3. 1
      src/views/agent/home.vue

2
.env.development

@ -1 +1 @@
VUE_APP_BASE_API=http://adminnew.pengda.checkcopy.com VUE_APP_BASE_API=http://agentnew.pengda.checkcopy.com/api

20
src/utils/request.js

@ -1,12 +1,11 @@
// src/utils/request.js // src/utils/request.js
import axios from "axios"; import axios from "axios";
import qs from 'qs';
import { handleTokenRefresh } from '@/utils/loginRefresh'; import { handleTokenRefresh } from '@/utils/loginRefresh';
import { host } from '@/config/host'; import { host } from '@/config/host';
// 创建 axios 实例 // 创建 axios 实例
const service = axios.create({ const service = axios.create({
baseURL: 'http://adminnew.pengda.checkcopy.com', // 从环境变量中读取 API 基础地址 baseURL: process.env.VUE_APP_BASE_API, // 从环境变量中读取 API 基础地址
timeout: 60000, // 请求超时时间 timeout: 60000, // 请求超时时间
headers: { headers: {
'Content-Type': 'application/x-www-form-urlencoded' 'Content-Type': 'application/x-www-form-urlencoded'
@ -99,26 +98,11 @@ const request = (method, url, data = {}, config = {}) => {
...config, ...config,
}); });
} else { } else {
let requestData = data;
// 如果 Content-Type 是 application/x-www-form-urlencoded,进行序列化
if (
config.headers &&
config.headers['Content-Type'] === 'application/x-www-form-urlencoded'
) {
requestData = qs.stringify(data);
} else if (
!config.headers &&
service.defaults.headers['Content-Type'] === 'application/x-www-form-urlencoded'
) {
requestData = qs.stringify(data);
}
// 其他请求(POST, PUT, DELETE 等)将参数放在请求体中 // 其他请求(POST, PUT, DELETE 等)将参数放在请求体中
return service({ return service({
method: lowerCaseMethod, method: lowerCaseMethod,
url, url,
data: requestData, data,
...config, ...config,
}); });
} }

1
src/views/agent/home.vue

@ -240,7 +240,6 @@ export default {
this.getExpireServices() this.getExpireServices()
this.getWalletList() this.getWalletList()
this.getNoticeList() this.getNoticeList()
console.log('API baseURL:', process.env.VUE_APP_BASE_API);
}, },
methods: { methods: {
getSupplyServiceList() { getSupplyServiceList() {

Loading…
Cancel
Save