vue如何路由跳转

vue
597
2021/5/10 8:37:01
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在vue中实现路由跳转的方法有:1.使用this.$router.push()跳转;2.使用router-link跳转;vue如何路由跳转

在vue中实现路由跳转的方法有以下几种

1.使用this.$router.push()跳转

1)不带参跳转

this.$router.push('/home')

this.$router.push({name:'home'})

this.$router.push({path:'/home'})

2)带参跳转

this.$router.push({name:'home',query: {id:'1'}})

this.$router.push({path:'/home',query: {id:'1'}})

this.$router.push({name:'home',params: {id:'1'}})

2.使用router-link跳转

1)不带参跳转

<router-link :to="{name:'home'}"> 

<router-link :to="{path:'/home'}">

2)带参跳转

<router-link :to="{name:'home', params: {id:1}}">
<router-link :to="{name:'home', query: {id:1}}">

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: vue的background怎么用