Home > Net >  How to pass shared props in several child components in Vue?
How to pass shared props in several child components in Vue?

Time:12-03

In react I can declare some 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?

Note that I'm not interesting in v-bind:shared_props="shared_props" because it's not the same.

CodePudding user response:

You can do it in this way :

<ChildComponent1 v-bind="shared_props" />

see more answers: https://github.com/vuejs/vue/issues/4962

  • Related