1.window.location
实例:http://www.myurl.com:8866/test?id=123&username=xxx
当前URL
| window.location.href |
| 结果:http: |
协议
| 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 reg=/[?&]([^?&#]+)=([^?&#]+)/g; |
| var param={}; |
| var ret = reg.exec(url); |
| while(ret){ |
| param[ret[1]]=ret[2]; |
| ret = reg.exec(url); |
| } |
| console.log(param) |
获取’?'前边的URL
| window.location.origin() |
| 结果:http: |
获取#之后的内容
| window.location.hash |
| 结果:null |
2.vue-router 获取参数
this.$route
this.$route.fullPath
this.$route.hash
this.$route.matched
this.$route.params
this.$route.query
本文作者:轻风细雨_林木木
本文链接:https://www.cnblogs.com/linzhifen5/p/16960960.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步