About the use of process.env.VUE_APP_BASE_URL

process.env.VUE_APP_BASE_URLIt 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_ENVThe value can be development, productionor test, used to distinguish different environments.

Vue.js will NODE_ENVautomatically load the corresponding environment configuration file according to the value of , such as .env.developmentor .env.production.

In addition, VUE_APP_TITLE='loc'it is a custom environment variable. process.env.VUE_APP_TITLEThis variable can be accessed in Vue.js code via .

process.env.VUE_APP_BASE_URLYou can access this value         from anywhere in your Vue.js project .

When running the project, you can use --modethe 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"
  },

おすすめ

転載: blog.csdn.net/m0_66675766/article/details/130082827