vue.js用vue-router路由传参时页面刷新后参数消失的问题
如果要用 params 传参的话,可能需要在你的路由路径里也加上这个参数,比如你用this.$router.push({name:'detail', params:{userId: userId}});跳转,那么在路由里就要这样写this.$router.push({name:'Detail',params:{pro_id:pro_id}});router - index.js 路...
·
如果要用 params 传参的话,可能需要在你的路由路径里也加上这个参数,比如你用this.$router.push({name:'detail', params:{userId: userId}});
跳转,那么在路由里就要这样写
this.$router.push({name:'Detail',params:{pro_id:pro_id}});
router - index.js 路由设置,参数名保持一致。
{
path: '/Detail/:pro_id',
name: 'Detail',
component: Detail
},
其中这里的router里的 path:'/
Detail
/:pro_id
',
里的:
是必须要有的。方可保证页面在用户重新刷新后,页面的参数不会丢失报错pro_id
跳转后,获取参数:
console.log(this.$route.params.userId)
注意:是 $route ......
具体的可以参考 Vue-router 命名路由
更多推荐
已为社区贡献22条内容
所有评论(0)