From a111fcc574d0d1ec0c045aadd420396606ee782b Mon Sep 17 00:00:00 2001 From: zhangyiming Date: Fri, 20 Nov 2020 08:48:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=8E=AF=E5=A2=83=E5=8F=98?= =?UTF-8?q?=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 1 + .env.development | 2 ++ .env.production | 2 ++ src/views/login.vue | 4 ++++ vite.config.ts | 11 ++++++++++- 5 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 .env create mode 100644 .env.development create mode 100644 .env.production diff --git a/.env b/.env new file mode 100644 index 000000000..b6a0dfb3b --- /dev/null +++ b/.env @@ -0,0 +1 @@ +VUE_APP_PROXY_DOMAIN = http://127.0.0.1:3000 \ No newline at end of file diff --git a/.env.development b/.env.development new file mode 100644 index 000000000..2e7205fb2 --- /dev/null +++ b/.env.development @@ -0,0 +1,2 @@ +# 只在开发模式中被载入的环境变量 +VUE_APP_PROXY_DOMAIN = http://127.0.0.1:3000 diff --git a/.env.production b/.env.production new file mode 100644 index 000000000..68fe5c033 --- /dev/null +++ b/.env.production @@ -0,0 +1,2 @@ +# 只在生产模式中被载入的环境变量 +# VUE_APP_PROXY_DOMAIN= 服务地址 diff --git a/src/views/login.vue b/src/views/login.vue index bdcdbedc8..04734fe25 100644 --- a/src/views/login.vue +++ b/src/views/login.vue @@ -13,6 +13,10 @@ const contextInfo: ContextProps = { dynamicText: "登录", } export default { + mounted() { + // @ts-ignore + this.$http.request("get", "/getApi") + }, components: { info, }, diff --git a/vite.config.ts b/vite.config.ts index 24a893586..391bdaf47 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -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/, '') }