1、vue獲取當(dāng)前頁面完整地址:window.location.href
2、獲取前面固定地址:window.location.host
關(guān)于window.location的詳解:
window.location 對(duì)象不僅可以獲得當(dāng)前頁面的地址 (URL),還能夠?qū)g覽器重定向到新的頁面。
下面,以http://www.xxxxxx.com:8000/test?id=123&username=xxx為例來進(jìn)行解釋:
1.?window.location.href?(當(dāng)前url)—— http://www.xxxxxx.com:8000/test?id=123&username=xxx
2.?window.location.protocol(協(xié)議)——?http:
3.?window.location.host(域名 + 端口)—— www.xxxxxx.com:8000
4.?window.location.hostname(域名)—— www.xxxxxx.com
5.?window.location.port(端口)—— 8000
6.?window.location.pathname(路徑)—— /test
7.?window.location.search?(請(qǐng)求的參數(shù))—— ?id=123&username=xxx文章來源:http://www.zghlxwxcb.cn/news/detail-500922.html
8.?window.location.origin(路徑前面的url)——??http://www.xxxxxx.com:8000文章來源地址http://www.zghlxwxcb.cn/news/detail-500922.html
到了這里,關(guān)于vue獲取當(dāng)前頁面地址的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!