vue获取url路径

vue中获取url路径
需要使用window.location.[options]

我们先弹出看一下window.location会显示什么?

 alert(window.location);

在这里插入图片描述
/sys-user为当前vue的路径
在这里插入图片描述

options属性有如下

属性描述
hash从#号开始的RUL
hostname主机名和当前URL的端口
herf完整的URL
pathname当前URL的路径部分
port当前URL的端口
protocol当前URL协议
search从问号(?)开始的URL(查询部分)
alert(window.location.hash)

在这里插入图片描述

 alert(window.location.host);

在这里插入图片描述

alert(window.location.hostname);

在这里插入图片描述

 alert(window.location.href);

在这里插入图片描述

alert(window.location.pathname);

在这里插入图片描述


 alert(window.location.port);

在这里插入图片描述

 alert(window.location.protocol);

在这里插入图片描述


 alert(window.location.search);

//获取全路径url "?“及”?"后面的值
http://localhost:86/detail?XXX=YYY
可以取到:?XXX=YYY

比如: http://localhost:8080/#/test?limitUserName=test&grade=0 像这种路径,取到的就是空值

因为查询字符串search只能在取到“?”后面和“#”之前的内容,如果“#”之前没有“?”search取值为空。

原文链接:https://blog.csdn.net/qq_42262444/article/details/115619457

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值