查看当前路由:
完整url可以用 window.location.href
路由路径可以用 this.$route.path
路由路径参数 this.$route.params
返回上一页和下一页
go () {
this.$router.go(-1) // 返回上一页
},
go2 () {
this.$router.go(1) // 返回下一页
}
1.query方式传参和接收参数
传参:
tochat () {
this.$router.push({
path: '/item',
query: {
id: 'item'
}
})
}
接收参数:
this.$route.query.id
2.params方式传参和接收参数
传参:
toindex () {
this.$router.push({
name: 'Home',
params: {
id: 'index'
}
})
}
接收参数:
this.$route.params.id
3、区别
query方法:可以在游览器上查看到传递的参数
params方法:无法在游览器上查看到传递的参数