【前端JS跳转篇】

本文介绍了如何使用JavaScript进行网页导航操作,包括利用window.history.go()和window.history.back()进行后退和前进,使用window.location.reload()刷新页面,以及在Vue中进行路由跳转的方法。这些函数可以帮助开发者实现页面无刷新前进、后退以及刷新等常见需求。
摘要由CSDN通过智能技术生成

js实现后退、前进、刷新

1. 返回上一页(-1不是返回一个,-2不是返回两个)

  • window.history.go(-1);
    区别:go方式会返回并保留数据(如表单中的数据)。
  • window.history.back(-1);
    区别:back方式会返回并刷新数据。

2. 前进一页

  • window.history.go(1);
  • window.history.forward();

3. 刷新

  • window.location.reload();

vue路由跳转到上一次的页面
//this.$router.go(-1)

  //指定跳转的地址
  //this.$router.replace('/learn')

  //指定跳转路由的名字下
  //this.$router.replace({name:'menuLink'})

  //通过push进行跳转
  this.$router.push("/learn");
  //this.$router.push({name:'/learn'})

总结:

<input type=button value=刷新 οnclick="window.location.reload()">
<input type=button value=前进 οnclick="window.history.go(1)">
<input type=button value=后退 οnclick="window.history.go(-1)">
<input type=button value=前进 οnclick="window.history.forward()">
<input type=button value=后退 οnclick="window.history.back()"> //后退+刷新
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值