【问题标题】:conditionally send props to child element Vue js有条件地向子元素Vue js发送道具
【发布时间】:2020-11-06 15:22:00
【问题描述】:

我想通过这个例子有条件地向 Quantity 组件发送道具。

<v-card
 class="mx-auto"
 max-width="344"
 shaped
 v-for="(item, index) in allItems || orderedItems"
 :key="index"
>

<Quantity {allItems ? :Items = item : :Ordered = item} />

</v-card>

如果orderedItems 被激活,我想发送 Ordered 道具,如果allItems 被激活,我想发送Items

【问题讨论】:

    标签: javascript vue.js vuejs2 vue-props


    【解决方案1】:

    改用v-bind

    <Quantity v-bind="quantityProps" />
    

    然后为此创建一个方法:

    quantityProps(item) {
      return {
        [this.allItems ? 'Items' : 'Ordered']: item
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2020-05-04
      • 2019-02-27
      • 2021-07-29
      • 2021-07-01
      • 2023-03-14
      • 2020-06-16
      • 2021-09-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多