首页IT科技vue获取当前行(Vue获取url路由地址、参数)

vue获取当前行(Vue获取url路由地址、参数)

时间2025-09-19 12:19:23分类IT科技浏览5561
导读:1.window.location...

1.window.location

实例:http://www.myurl.com:8866/test?id=123&username=xxx

当前URL

window.location.href 结果:http://www.myurl.com:8866/test?id=123&username=xxx

协议

window.location.protocol 结果:http

域名 + 端口

window.location.host 结果:www.myurl.com:8866

域名

window.location.hostname() 结果:www.myurl.com

端口

window.location.port() 结果:8866

路径部分

window.location.pathname() 结果:/test

请求的参数

window.location.search 结果:?id=123&username=xxx

备注:获取参数

// var url="www.baidu.com?a=1&b=2&C=3";//测试地址 /* * 分析:最前面是?或&                  ,紧跟着除 ?&#以外的字符若干 * 然后再等号                        ,最后再跟着除 ?&#以外的字符 * 并且要分组捕获到【除?&#以外的字符】 */ var reg=/[?&]([^?&#]+)=([^?&#]+)/g; var param={}; var ret = reg.exec(url); while(ret){ // 当ret为null时表示已经匹配到最后了        ,直接跳出 param[ret[1]]=ret[2]; ret = reg.exec(url); } console.log(param)

获取’?前边的URL

window.location.origin() 结果:http://www.myurl.com:8866

获取#之后的内容

window.location.hash 结果:null

2.vue-router 获取参数

this.$route

this.$route.fullPath

this.$route.hash

this.$route.matched

this.$route.meta

this.$route.params

this.$route.query

声明:本站所有文章              ,如无特殊说明或标注                         ,均为本站原创发布                。任何个人或组织            ,在未征得本站同意时         ,禁止复制                  、盗用                        、采集        、发布本站内容到任何网站              、书籍等各类媒体平台                          。如若本站内容侵犯了原著者的合法权益                          ,可联系我们进行处理        。

创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

展开全文READ MORE
python如何合并两个list(在Python中如何合并两个数据框)