vue返回上一页(后退)的几种方法与区别,go或者back 附有代码-前端-阿习进阶博客
Java
MySQL
大数据
Python
前端
黑科技
    首页 >> 互联网 >> 前端

vue返回上一页(后退)的几种方法与区别,go或者back 附有代码

[导读]:方法:①. 若项目使用vue-router,this.$router.go(-1)可以回到上一页②.this.$router.back()③.window.history.go(-1)区别①与②的区别是:go(-1): 原页面表单中的内容会丢失:1.this.$router.go(-1):后退+刷新;2.this.$router.go(0):刷新;3.this.$router.go(1...

方法:

image.png

①. 若项目使用vue-router,this.$router.go(-1)可以回到上一页

②. this.$router.back()
③. window.history.go(-1)

区别

①与②的区别是:

go(-1): 原页面表单中的内容会丢失:

 1. this.$router.go(-1):后退+刷新;
 2. this.$router.go(0):刷新;
 3. this.$router.go(1):前进;

back(): 原页表表单中的内容会保留;

 1. this.$router.back():后退 ;
 2. this.$router.back(0):刷新;
 3. this.$router.back(1):前进;

③的区别是:

history.go(-1)是返回浏览器的上一页,而由于Vue是单页面应用,有的浏览器对于hash变更不认为是两个不同的页面,在hash模式下就不会跳回浏览器上一页


本文来自阿习进阶博客,如若转载,请注明出处:https://yanxias.com

留言区

联系人:
手   机:
内   容:
验证码:

历史留言

联系人:阿习

手机号:156****7890

留言内容:欢迎大家一起讨论文章,有喜欢发帖的可以私聊我给你开权限,发文章

留言时间:2022-05-09 17:46:15

回复内容:互联网阿习

回复时间:2022-05-09 17:46:15

用户IP:220.***.***.232

用户操作系统:Windows 10

欢迎加Easy的QQ