The interface accessed after vue deployment calls http://localhost:8080/ instead of its own actual interface (solved)

After deployment he visits the

Solving this problem is simple

Let's first look at the configuration of the following files in vue

.env The configuration file loaded regardless of the development environment or the production
environment.env.development The configuration file loaded by the development environment.env.production The
configuration file loaded by the production environment

Why do we load .env.development locally and load .env.production on the server? ?
When we usually start through npm run serve, the value of the environment variable NODE_ENV of our local system is set to development, and then the two files .env and .env.development will be loaded successively.
And when we package to the server, the NODE_ENV value of the server is set to production, then Vue will still load the .env file first, and then load the .env.production file.

Emphasize: process.env.NODE_ENV has only two states by default, development and production. Development refers to local development, that is, the localhost environment (local development), and production represents services published on any service (whether dat, uat or production Environment), node does not know whether your service is a test or official, unless you specify it manually. It is generally considered to be an online environment. So it can be considered that development represents the local development environment, and production represents the online environment (including dat, uat and production environment, etc.

So we only need to modify the VUE_app_BASE_API of .env.production

 

Guess you like

Origin blog.csdn.net/Z_Gleng/article/details/124895263