您的位置:首页 > 产品设计 > UI/UE

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

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

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

其中这里的routes里的
path:'/
detail
/:[code]userId
'[/code]
,
里的
:
userId

是必须要有的。

跳转后,获取参数:

console.log(this.$route.params.userId)

注意:是 $route   ......

具体的可以参考
Vue-router 命名路由
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: