My Vue learning record 1: front end cross domain proxy configuration

Time:2021-11-26

Cross domain configuration

In the vue.config.js file under the root directory of the project directory, add the following code

module.exports = {
    publicPath: "/",
    devServer: {
      proxy: {
        "/api": {
          target: " http://127.0.0.1:9001/api ", // requested address
          changeOrigin: false,
          pathRewrite: {
            "^ / API": "", // the address prefix of Axios used later can be replaced by / API
          },
        },
      },
    },
  };

This work adoptsCC agreement, reprint must indicate the author and the link to this article

If there is any mistake, you are welcome to give advice