Vue-cli local environment API proxy settings solve cross-domain problems

Agent has been configured

clipboard.png

ip404

clipboard.png

Mar.11,2021

pathRewrite : {
'^/api': ''
}

first, look at the / api string in the interface.

if not (there should be no error message), then / api is just a flag you set to tell the local node server to proxy the corresponding interface across domains through the / api flag.

therefore, in the proxyTable configuration item, you need to rewrite / api to ensure normal access to the interface through pathRewrite .

however, the configuration you write will add the string / api to the interface, resulting in a request for 404:

.
...
pathRewrite : {
'^/api': '/api'
}
...

the correct one should be:

...
pathRewrite : {
'^/api': ''
}
...
Menu