Vue-cli3.0 .env.development cannot get the devServer.proxy in vue.config.js

the environmental background of the problems and what methods you have tried

Development environment: vue 3.0.4
vue-cli 3.0
node v8.11.0

related codes

.env.development file code

VUE_APP_BASE_API=/api

vue.config.js file code

module.exports = {
  productionSourceMap: false,
  assetsDir: "static/xxx",
  devServer: {
    proxy: {
      "/api": {
        target: "https://www.xxx.com",
        changeOrigin: true,
        pathRewrite: {
          "^/api": ""
        }
      }
    }
  }
};


clipboard.png
finally print

in the request.js encapsulating axios
console.log("request", process.env.VUE_APP_BASE_API);
 /api

what result do you expect?

does not print a cross-domain address. I hope someone can take a look at it

.
Sep.30,2021

'/ api'

print definitely printed api have your requested address changed? I see nothing wrong with your configuration

I have the same problem solved

Menu