vue-router的基本使用

路由跳转

1
2
3
4
5
6
7
8
// 字符串
this.$router.push('/home/first')

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

// 命名的路由
this.$router.push({ name: 'home', params: { userId: wise }})

传参

query

1
2
3
http://192.168.1.12:8080/#/detail/?id=123

let id = this.$route.query.id

params

1
2
3
4
5
6
7
8
9
10
{
path: '/detail/:id/',
name: 'detail',
component: detail,
meta: {
title: '详情'
}
}

let id = this.$route.params.id

监听路由变化

1
2
3
4
5
watch:{
$route(to,from){
console.log(to.path);
}
}
Yvan Zhu wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!
0%