@vue/ CLI Interconnects with the backend for cross-domain configuration in the development environment

Vue. Config. js file configuration

DevServer: {proxy: {'/ API ': {// here/API is axios baseURL target: 'http://127.0.0.1:8080', // request interface domain name ws: True, // To proxy websockets, configure this parameter changeOrigin: true, // enable cross-domain pathRewrite: {'^/ API ': "// replace the request address}}}}} in targetCopy the code
Understand the meaning of proxy configuration in VUE: When we request data from localhost:8080 to localhost:3000, due to the same origin policy of the browser, the cross-domain request cannot be successful, but the local node server can make the request by running the vue project. Therefore, we use the data request agent of localhost:9000 to request data of port 3000 in node local runtime environment.
Note: The proxy configured in the VUE project only proxies localhost requests in the development environment to www.xxx.com. When the project is published to the production environment, it goes to the Nginx proxy server, and the proxy configuration in the project is invalid.