位置:- 正文

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

编辑:rootadmin
Vue获取url路由地址、参数 文章目录1.window.location当前URL协议域名 + 端口域名端口路径部分请求的参数获取’?'前边的URL获取#之后的内容2.vue-router 获取参数this.$routethis.$route.fullPaththis.$route.hashthis.$route.matchedthis.$route.metathis.$route.paramsthis.$route.query1.window.location

推荐整理分享Vue获取url路由地址、参数(vue获取当前路由地址),希望有所帮助,仅作参考,欢迎阅读内容。

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

文章相关热门搜索词:vue 获取url参数,vue怎么获取地址栏的路由地址,vue怎么获取地址栏的路由地址,vue获取url参数不是路由传参,vue获取路径,vue怎么获取地址栏的路由地址,vue获取当前路由地址,vue获取当前路由地址,内容如对您有帮助,希望把文章链接给更多的朋友!

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

当前URLwindow.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)获取’?'前边的URLwindow.location.origin()结果:http://www.myurl.com:8866获取#之后的内容window.location.hash结果:null2.vue-router 获取参数this.$routethis.$route.fullPaththis.$route.hashthis.$route.matchedthis.$route.metathis.$route.paramsthis.$route.query
本文链接地址:https://www.jiuchutong.com/zhishi/292316.html 转载请保留说明!
下一篇链接:https://www.jiuchutong.com/zhishi/292317.html
免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

鄂ICP备2023003026号

友情链接: 武汉网站建设 电脑维修 湖南楚通运网络