process.env.VUE_APP_BASE_URL
It is an environment variable used in Vue.js and can be used to store the base URL address of an application, such as the address of an API server.
In Vue CLI 3 and above, when you create a .env.[mode]
file named in the project root directory; where [mode] is your mode name, for example .env.development
, and set the value in it VUE_APP_BASE_URL
, then this value will be automatically injected into the project. as follows:
Here we create an .
env .
dev and .
env .
production
Take .
env .
production as an example:
// 在.env.production文件中
NODE_ENV='production'
VUE_APP_TITLE='prod'
/* 请求接口地址 */
VUE_APP_BASE_URL = 'https://lxxx.sxxx.com'
In this configuration, NODE_ENV='
production ' indicates that the current running environment is the development environment.
NODE_ENV
The value can be development
, production
or test
, used to distinguish different environments.
Vue.js will NODE_ENV
automatically load the corresponding environment configuration file according to the value of , such as .env.development
or .env.production
.
In addition, VUE_APP_TITLE='loc'
it is a custom environment variable. process.env.VUE_APP_TITLE
This variable can be accessed in Vue.js code via .
process.env.VUE_APP_BASE_URL
You can access this value from anywhere in your Vue.js project .
When running the project, you can use --mode
the parameter to specify which environment file to use, for example:
// 在package.json文件中
"scripts": {
"dev": "vue-cli-service serve --mode dev",
"build": "vue-cli-service build --mode production"
},