vue-router传递参数
查询参数其实就是在路由地址后面带上参数和传统的url参数一致的,传递参数使用query而且必须配合path来传递参数而不能用name,目标页面接收传递的参数使用query。
注意:和name配对的是params,和path配对的是query
使用方法如下:
query
router 正常写
传递参数 this.$router.push({ path: '/news', query: { userId: 123 }});
运行效果:localhost:8080/news?userId=123
接收参数 this.$route.query.userId
params
const router = new VueRouter({
routes: [
{ path: '/news/:id', component: User }
]
})
传递参数 this.$router.push({ name: 'news', params: { userId: 1111}})
运行效果:localhost:8080/news
接收参数 this.$route.params.userId
浙公网安备 33010602011771号