Exception handling on vue-resource request cross-domain

 

When you start a vue project, the project will be run on a webpack service, so at this time to visit other ports or other addresses belonging to the cross-domain requests, it will be reported anomalies.

 

has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

 

When this exception occurs, do not panic, the solution is simple.

First, open the project file webpack.config.js

In the current search page 

devServer:

 

Then add the following object under this node:

name can be named, but the best are named in a certain format, a little later will be used later. Here is the code for this object

proxy: {
'/api': {
target: 'http://localhost:64938/',
changeOrigin: true,
  }
}

After adding objects, back to the page we call request, the request to modify the url corresponding to the error, the original request with url address is as: http: // localhost: 64938 / Replace / api, and then restart the project! Restart project! Restart project!

Restart the project, you can visit!

 

 

Guess you like

Origin www.cnblogs.com/blogsaspx/p/11256455.html