Vue in axios solution of cross-domain requests proxyTable

Cross-domain , referring to the browser can not execute scripts other sites. It is caused by the browser's same-origin policy is a browser for JavaScript security restrictions imposed.

 

The so-called homologous refers to the domain, protocol, port are the same, do not understand it does not matter, give chestnuts:

http://www.123.com/index.html call http://www.123.com/server. PHP  (non-cross-domain)

http://www.123.com/index.html call http://www.456.com/server. PHP  (different main domain: 123/456, cross-domain)

http://abc.123.com/index.html call http://def.123.com/server.php (subdomain different: abc / def, cross-domain)

Call http://www.123.com:8081/server.php (different ports: 8080/8081, cross-domain) http://www.123.com:8080/index.html

http://www.123.com/index.html call https://www.123.com/server.php (different protocols: http / https, cross-domain)

Please note: localhost 127.0.0.1 and although point to the machine, but also a cross-domain.

Browser execute javascript script, the script will check belongs to which page, if not homologous to the page, it will not be executed.

 

Solution:

0. agent

 

Vue in the config file index.js folder, the writing in the cross-domain configuration item proxyTable object, as shown below:

Will / api request basis for the beginning of the URL address Replace http: // localhost: 8888

Then baseURL changed / api

 

 

 

 

Guess you like

Origin www.cnblogs.com/Faith-Yin/p/12443770.html