首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >for循环中的Vue插槽作用域

for循环中的Vue插槽作用域
EN

Stack Overflow用户
提问于 2019-03-05 22:13:03
回答 1查看 1.5K关注 0票数 0

我在v-for循环中有多个插槽,如下所示。有没有一种方法可以将这些数据绑定到v-for循环中的所有插槽,而不是为每个插槽绑定数据?

代码语言:javascript
复制
<div class="vehicle-listing" v-for="(vehicle, index) in vehicles" :key="vehicle.id ? vehicle.id : 'undefined'+index">

    <div class="vehicle-listing__image">
        <slot name="listing-image" v-bind:vehicle="vehicle">
            Default content
        </slot>
    </div>

    <div class="vehicle-listing__title">
        <slot name="listing-title" v-bind:vehicle="vehicle">
            <slot name="listing-title__header" v-bind:vehicle="vehicle">
                Default content
            </slot>
            <slot name="listing-title__subtitle" v-bind:vehicle="vehicle">
                Default content
            </slot>
            <slot name="listing-title__price" v-bind:vehicle="vehicle">
                Default content
            </slot>
            <slot name="listing-title__favourites" v-bind:vehicle="vehicle">
               Default content
            </slot>
        </slot>
    </div>

    <div class="vehicle-listing__summary">
        <slot name="listing-summary" v-bind:vehicle="vehicle">
            Default content
        </slot>
    </div>

    <div class="vehicle-listing__finance">
        <slot name="listing-finance" v-bind:vehicle="vehicle">
            Default content
        </slot>
    </div>

    <div class="vehicle-listing__info">
        <slot name="listing-info" v-bind:vehicle="vehicle">
           Default content
        </slot>
    </div>

    <div class="vehicle-listing__location">
        <slot name="listing-location" v-bind:vehicle="vehicle">
           Default content
        </slot>
    </div>

    <div class="vehicle-listing__button-block">
        <slot name="listing-cta" v-bind:vehicle="vehicle">
           Default content
        </slot>
    </div>

</div>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-05 22:24:51

不,没有一次绑定到所有插槽的方法。您需要分别为每个插槽提供绑定。

https://vuejs.org/v2/guide/components-slots.html#Scoped-Slots

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55004817

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档