新建'.env' (和vite.config.js同一个路径下)
VITE_APP_API_URL=http://localhost
vite.config.js
import { defineConfig, loadEnv } from 'vite' export default defineConfig((mode) => { const env_config = loadEnv(mode, process.cwd()) const VITE_APP_API_URL = env_config.VITE_APP_API_URL console.log(VITE_APP_API_URL) return { // 构建参数 build: { sourcemap: false }, base: '', plugins: [vue()], resolve: { alias: { '@': path.resolve(__dirname, './src') } }, server: { // host域名或者IP host: 'localhost', port: 8087, // 其他配置。。。 proxy: { '/v1/': { target: VITE_APP_API_URL + '/v1/', ws: true, secure: false, changeOrigin: true, rewrite: (path) => path.replace(/^\/v1\//, '') } } } })
启动时就可以看到日志打印
标签:VUE,URL,APP,API,vite,config,环境变量,VITE From: https://www.cnblogs.com/leonlipfsj/p/18137190