Vue summary of the study --- cross-domain issues before and after the end of the separation mode to solve the Vue project development environment

Original: https: //blog.csdn.net/localhost_1314/article/details/83623526 

Separate back-end web development front, we FBI and background, experience cross-domain problems.

such as:

Development address is localhost: 8080, need access to localhost: 9000 interface.

Access between different domain names, you need to cross-domain requests properly. A lot of cross-domain method, the Vue-cli project created, you can directly use Node.js proxy server, cross-domain requests.

Solution:

Axios mounted
in the baseURL main.js in a global configuration, not one by one so that the modified url, it functions as an interceptor, when the request to the context address match, the agent can cross-domain request


 

3. Add configuration items proxyTable in config -index.js in the dev:

 

among them:

'/ Apis' is a match, the matching interception

target address requested (usually develop in the background by the local interface address)

pathRewrite to rewrite the configuration, because the addition of the prefix '/ apis' in the ajax url, whereas the interface is not the original prefix, it is necessary to rewrite pathRewrite address, the prefix '/ apis' Switch '';

If the address of the interface itself, there '/ apis' this common prefix, you can pathRewrite deleted.

Heads for the https address, when needed https requests only needs to be set.


Guess you like

Origin www.cnblogs.com/qcq0703/p/10964382.html