Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
473 views
in Technique[技术] by (71.8m points)

vue 路由组件传参没看懂

https://router.vuejs.org/zh/g...

我没看懂,如何理解?
当props被设置为true时,$route.params是不是就被绑定到了组件的props的id属性上??
如果组件有多个props属性怎么解决的呢?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

传递多个参数:

this.$router.push({
    name:'Component1',
    params:{id:123, userName:'hangge'}
});
如果props被设置为trueroute.params将会被设置为组件属性。

意思是在组件中不需要使用 $route.params.x 获取传递的参数了,可以直接在模板中使用:

<p>ID:{{ id }}</p>
<p>用户名:{{ userName}}</p>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...