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/, '') }