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

xiaoxiao2021-02-28  71

如果要用 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 命名路由

转载请注明原文地址: https://www.6miu.com/read-56853.html

最新回复(0)