Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a024e8f

Browse files
committed
fix
1 parent 40a456a commit a024e8f

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

websitefronted/src/main.js

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,14 @@ Vue.use(ViewUI)
1818
console.log('env',process.env.NODE_ENV,process.env.BASE_API)
1919

2020
//根据环境匹配api地址
21-
// axios.defaults.baseURL = process.env.BASE_API
22-
let protocol = window.location.protocol; //协议
23-
let host = window.location.host; //主机
24-
let reg = /^localhost+/;
25-
if (reg.test(host)) {
26-
//若本地项目调试使用
27-
axios.defaults.baseURL = 'http://127.0.0.1:8000';
28-
} else {
29-
//动态请求地址 协议 主机
30-
axios.defaults.baseURL = protocol + "//" + host + ":80";
21+
if (process.env.NODE_ENV === 'development') {
22+
axios.defaults.baseURL = 'http://127.0.0.1:8000/'
23+
}else if(process.env.NODE_ENV === 'production'){
24+
axios.defaults.baseURL = window.location.protocol + "//" + window.location.host +":80";
3125
}
3226
//请求超时时间
3327
axios.defaults.timeout = 10000 //超时10秒
3428

35-
let protocol = window.location.protocol; //协议
36-
let host = window.location.host;
37-
axios.defaults.baseURL = protocol + "//" + host +":80";
38-
3929
axios.interceptors.request.use(config => {
4030
if (localStorage.token) {
4131
config.headers.Authorization = 'JWT ' + localStorage.token

0 commit comments

Comments
 (0)