温馨提示×

vue中路由跳转的方式有哪些

养鱼的猫咪
360
2021-03-29 14:44:17
栏目: 编程语言
Vue开发者专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

vue中实现路由跳转的方式有:1.通过router-link标签跳转;2.通过this.$router.push()事件跳转;3.通过this.$router.go(n)事件跳转;

vue中路由跳转的方式有哪些

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

1.通过router-link标签跳转

// 配置路由

path: '/user/:id'

<router-link :to="'/user/' + this.id"> <router-link/>

// 接收参数

this.$route.params.id

2.通过this.$router.push()事件跳转

1)跳转字符串

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

2)跳转对象

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

3.通过this.$router.go(n)事件跳转

this.$router.go(1)

// 后退一步记录

this.$router.go(-1)

// 前进三步记录

this.$router.go(3)

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

推荐阅读:vue中路由有哪些懒加载方式

0