Skip to content

Commit 09ecc2f

Browse files
committed
接口联调配置修改
1 parent e9ae954 commit 09ecc2f

File tree

6 files changed

+21
-20
lines changed

6 files changed

+21
-20
lines changed

.env.development

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
ENV = 'development'
22

33
# 接口地址,注意协议,如果你没有配置 ssl,需要将 https 改为 http
4-
VUE_APP_BASE_API = '42.194.194.178:3000'
4+
VUE_APP_BASE_API = 'http://localhost:3000'
55
# 如果接口是 http 形式, wss 需要改为 ws
6-
VUE_APP_WS_API = '42.194.194.178:3000'
6+
VUE_APP_WS_API = 'ws://localhost:3000'
77

88
# 是否启用 babel-plugin-dynamic-import-node插件
99
VUE_CLI_BABEL_TRANSPILE_MODULES = true

.env.production

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ENV = 'production'
22

33
# 接口地址,注意协议,如果你没有配置 ssl,需要将 https 改为 http
4-
VUE_APP_BASE_API = '/'
4+
VUE_APP_BASE_API = 'http://42.194.194.178:3000'
55
# 如果接口是 http 形式, wss 需要改为 ws
6-
VUE_APP_WS_API = '/'
6+
VUE_APP_WS_API = 'ws://42.194.194.178:3000'

src/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import App from './App'
33
import router from './router'
44
import store from './store'
55

6-
// import './router/auth'
6+
import './router/auth'
77

88
import './assets/icon-fonts/iconfont.css'
99
import './assets/icon-fonts/iconfont'

src/request.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import { getToken } from './utils/cookie'
44

55
// 创建axios实例
66
const service = axois.create({
7-
baseURL: process.env.NODE_ENV === 'production' ? process.env.VUE_APP_BASE_API : '/', // api 的 base_url
7+
baseURL: process.env.VUE_APP_BASE_API, // api 的 base_url
88
timeout: 120000 // 请求超时时间
99
})
1010

1111
// request拦截器设置
1212
service.interceptors.request.use(
1313
config => {
1414
if (getToken()) {
15-
config.headers['Authorization'] = getToken() // 请求头设置自带 token
15+
config.headers['Authorization'] = 'Bearer ' + getToken() // 请求头设置自带 token
1616
}
1717
config.headers['Content-Type'] = 'application/json' // 请求的数据格式为 json
1818
return config
@@ -26,10 +26,11 @@ service.interceptors.request.use(
2626
// response 拦截器设置
2727
service.interceptors.response.use(
2828
response => {
29-
const code = response.code
30-
const message = response.msg
29+
const data = response.data
30+
const code = data.code
31+
const message = data.msg
3132
if (code === 0) {
32-
return response.data
33+
return data.data
3334
} else {
3435
Message({
3536
type: 'error',

src/store/modules/user.js

Whitespace-only changes.

vue.config.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@ module.exports = {
1414
name: name // 配置网页title 名称
1515
},
1616
devServer: {
17-
host: 'localhost', // 默认是 localhost,可不配置
17+
host: '0.0.0.0', // 默认是 localhost,可不配置
1818
port: port, // 配置端口号
1919
open: true, // 启动是否打开浏览器
2020
overlay: { // 是否在浏览器上显示编译的 errors 或 warnings
2121
warnings: false,
2222
errors: true
23+
},
24+
proxy: {
25+
'/': { // 被代理的接口名
26+
target: process.env.VUE_APP_BASE_API, // url地址
27+
changeOrigin: true, // 发送请求头中 host 是否设置成 target
28+
pathRewrite: { // 重定向
29+
'^/': ''
30+
}
31+
}
2332
}
24-
// proxy: {
25-
// '/': { // 被代理的接口名
26-
// target: process.env.VUE_APP_BASE_API, // url地址
27-
// changeOrigin: true, // 发送请求头中 host 是否设置成 target
28-
// pathRewrite: { // 重定向
29-
// '^/': ''
30-
// }
31-
// }
32-
// }
3333
}
3434
}

0 commit comments

Comments
 (0)