參考:https://www.jianshu.com/p/c9324d237a8e
關於window.location的詳解:
window.location 對象不僅可以獲得當前頁面的地址 (URL),還能夠將瀏覽器重定向到新的頁面。
下面,以http://www.myurl.com:8866/test?id=123&username=xxx
為例來進行解釋:
1. window.location.href (當前url)—— http://www.myurl.com:8866/test?id=123&username=xxx
2. window.location.protocol(協議)—— http:
3. window.location.host(域名 + 端口)—— www.myurl.com:8866
4. window.location.hostname(域名)—— www.myurl.com
5. window.location.port(端口)—— 8866
6. window.location.pathname(路徑)—— /test
7. window.location.search (請求的參數)—— ?id=123&username=xxx
8. window.location.origin(路徑前面的url)—— http://www.myurl.com:8866
main,js中:
··· import Axios from 'axios'; let path = '/contentPath' let url = window.location.origin +path; //path為上下文路徑,如果后端有配置就添加 Axios.defaults.baseURL = url;