简体   繁体   English

如何在 Vue 中的多个子组件中传递共享道具?

[英]How to pass shared props in several child components in Vue?

In react I can declare some object...在反应中我可以声明一些 object ...

const shared_props = {
  prop1: 'value1',
  prop2: 'value2',
  prop3: 'value3',
};

...and then pass it to several child components like this: ...然后像这样将它传递给几个子组件:

<ChildComponent1 {...shared_props} />
<ChildComponent2 {...shared_props} />
<ChildComponent3 {...shared_props} />

How can I do this in Vue?我怎样才能在 Vue 中做到这一点?

Note that I'm not interesting in v-bind:shared_props="shared_props" because it's not the same.请注意,我对v-bind:shared_props="shared_props"不感兴趣,因为它不一样。

You can do it in this way:你可以这样做:

<ChildComponent1 v-bind="shared_props" />

see more answers: https://github.com/vuejs/vue/issues/4962查看更多答案: https://github.com/vuejs/vue/issues/4962

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM