【问题标题】:How to pass shared props in several child components in Vue?如何在 Vue 中的多个子组件中传递共享道具?
【发布时间】:2022-12-03 22:26:34
【问题描述】:

在反应中我可以声明一些对象......

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

...然后像这样将它传递给几个子组件:

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

我怎样才能在 Vue 中做到这一点?

请注意,我对 v-bind:shared_props="shared_props" 不感兴趣,因为它不一样。

【问题讨论】:

    标签: reactjs vue.js vuejs2 vuejs3


    【解决方案1】:

    你可以这样做:

    <ChildComponent1 v-bind="shared_props" />
    

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

    【讨论】:

      猜你喜欢
      • 2018-08-11
      • 1970-01-01
      • 2021-12-02
      • 2021-12-02
      • 2017-10-10
      • 2020-12-04
      • 2019-11-12
      • 2019-05-31
      • 2020-10-19
      相关资源
      最近更新 更多