Skip to content

环境变量

增加 .env.development .env.production 文件

env
VUE_BASE_URL='/api/'  //vue2
VITE_BASE_URL='/api/' //vite
package.json中设置
json
{
  "scripts": {
    "serve": "vue-cli-service serve --mode development",
    "build": "vue-cli-service build --mode production",
    "lint": "vue-cli-service lint",
  },
}
使用 vue2
js
let url = process.env.VUE_BASE_URL;
vite
js
let url = import.meta.env.VITE_BASE_URL