路由传参方式params或者query
当我们使用params时。router/index.js中定义的路由后面一定要加参数
{
path: "/user/:id",
component: User,
meta: {
title: "用户信息"
}
}当我们请求这条路由时
this.$router.push({
name: 'user',
params: {
id: '1'
}
})
//或者
this.$router.push('/user/' + id)从路由中取数据
this.$route.params.id
query传参时,定义路由不需要增加参数
{
path: "/user",
component: User,
meta: {
title: "用户信息"
}
}请求路由
this.$router.push({
path: '/user',
query: {
id: '1'
}
})
//或者
data: {
id: 1
}
this.$router.push('/user/' + id)获取路由参数
this.$route.query.id



京公网安备 11010502036488号