vue 之this.$router.push、replace、go的区别


一、this.$router.push

说明:跳转到指定URL,向history栈添加一个新的记录,点击后退会返回至上一个页面

使用:

1 this.$router.push('/index')
2 this.$router.push({path:'/index'})
3 this.$router.push({path:'/index',query:{name: '123'}})
4 this.$router.push({name:'index',params:{name:'123'}})

  

二、this.$router.replace

说明:跳转到指定URL,替换history栈中最后一个记录,点击后退会返回至上上一个页面

使用:同push

 

三、this.$router.go(n)

说明:类似window.history.go(n),向前或向后跳转n个页面,n可正(先后跳转)可负(向前跳转)

使用:

this.$router.go(1)    //类似history.forward()

this.$router.go(-1)   //类似history.back()

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM