当前位置: 首页 > Web前端 > vue.js

[Vue]Vue-routerpush-replace-go使用区别

时间:2023-04-01 12:57:22 vue.js

1.this.$router.push()push跳转会在历史栈中添加一条记录,点击back返回上一页。A->B($router.push(“/c”))->C回到C页面后,会回到B页面。2.this.$router.replace()替换跳转不会在历史记录中添加新的记录,它会将B页的地址替换为C页的地址,回到C页,会跳转到该页的上一页B.A->B($router.replace(“/c”))->C回到C页面后,又回到A页面。3.this.$router.go(n)相对于当前页面向前或向后跳转多少页,类似于window.history.go(n)。n可以是正数或负数或0。this.$router.go(0)刷新当前页面。this.$router.go(3)//前3步记录this.$router.go(n)===window.history.go(n)注意:相当于调用router.push("/url")支持新页面打开发布在自己语雀https://www.yuque.com/diracke…