添加环境变量

This commit is contained in:
zhangyiming 2020-11-20 08:48:00 +08:00
parent a8ee79a443
commit a111fcc574
5 changed files with 19 additions and 1 deletions

1
.env Normal file
View File

@ -0,0 +1 @@
VUE_APP_PROXY_DOMAIN = http://127.0.0.1:3000

2
.env.development Normal file
View File

@ -0,0 +1,2 @@
# 只在开发模式中被载入的环境变量
VUE_APP_PROXY_DOMAIN = http://127.0.0.1:3000

2
.env.production Normal file
View File

@ -0,0 +1,2 @@
# 只在生产模式中被载入的环境变量
# VUE_APP_PROXY_DOMAIN= 服务地址

View File

@ -13,6 +13,10 @@ const contextInfo: ContextProps = {
dynamicText: "登录",
}
export default {
mounted() {
// @ts-ignore
this.$http.request("get", "/getApi")
},
components: {
info,
},

View File

@ -1,3 +1,12 @@
const dotEnv = require('dotenv')
const path = require('path')
const VUE_APP_ENV = 'development'
const resolve = dir => path.join(__dirname, dir)
const { VUE_APP_PROXY_DOMAIN } = dotEnv.config({
path: resolve(`.env.${VUE_APP_ENV}`)
}).parsed
module.exports = {
alias: {},
// 是否自动在浏览器打开
@ -18,7 +27,7 @@ module.exports = {
// 反向代理
proxy: {
'/api': {
target: 'http://127.0.0.1:3000',
target: VUE_APP_PROXY_DOMAIN,
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, '')
}