Vue中三种url跳转不刷新页面的方法

Vue中三种url跳转不刷新页面的方法

1.利用location.hash方法

location.hash ='qqqq'

2.利用history.pushState()的方法

history.pushState = ({},'','home')

3.利用history.replaceState()方法

history.replaceState({},'','home')

4.利用history.go()或者history.forward()

history.go(2)   

history.forward()

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
当使用Vue的`location.href`进行页面时,如果当前页面URLURL是相同的,页面可能不会刷新。这是因为`location.href`只会在URL发生改变时才会重新加载页面。例如,如果你想从页面B页面A,并且它们的URL是相同的(例如都是https://www.baidu.com),那么页面可能不会刷新。 另外,当使用`location.href`进行页面时,如果存在一个提交按钮并且在触发事件后会先提交表单,那么页面可能会失效。解决这个问题的方法是将按钮的类型从`submit`改为`button`。 如果你希望在刷新页面,可以在使用`window.location.href`后再使用`window.location.reload()`方法,这样页面会重新加载。 综上所述,如果你在Vue使用`location.href`进行并希望刷新页面,你可以尝试以下解决方案: 1. 确认URL和当前页面URL是否相同,如果相同,则可能不会刷新页面。 2. 如果存在一个提交按钮并且在触发事件后会先提交表单,考虑将按钮的类型改为`button`。 3. 在使用`window.location.href`后,使用`window.location.reload()`方法重新加载页面。 希望这些解决方案对你有帮助!<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [使用window.location.href页面刷新的问题](https://blog.csdn.net/u010856177/article/details/127306432)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* [window.location.href 失效问题解决办法](https://blog.csdn.net/qq_39506434/article/details/130256273)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

骨子里的偏爱

上传不易,还请多多支持。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值