vue.js用vue-router路由传参时页面刷新后参数消失的问题

来源:互联网 发布:长沙岳麓网络花店 编辑:程序博客网 时间:2024/05/22 03:29

如果要用 params 传参的话,可能需要在你的路由路径里也加上这个参数,比如你用
this.$router.push({name:'detail, params:{userId: userId}});跳转,那么在路由里就要这样写

routes: [    {      path: '/detail/:userId',      name: 'detail',      component:user }  ]

其中这里的routes里的 path:'/detail/:userId',里的:userId 是必须要有的。


跳转后,获取参数:

console.log(this.$route.params.userId)
注意:是 $route   ......


具体的可以参考 Vue-router 命名路由