A
A
Aleksandr2018-03-28 18:08:47
JavaScript
Aleksandr, 2018-03-28 18:08:47

Multiple slots in a component?

Interested in such a question, so I'm trying to make such a component record + modal

<template>
  <div class="main">
    <div class="main__news">
      <news-bar />
      <div class="news-wrap__right">
        <div class="news-block" @click="showModal = true">
          <div class="news-block__img" :style="`background-image: url(${news.img});`"></div>
          <div class="news__block__right">
            <span class="news-block__date">
              <slot name="date"></slot>
            </span>
            <p class="news-block__text">
              <slot name="title"></slot>
            </p>
            <span class="news-block__label">Мини-КАСКО</span>
          </div>
          <div class="main-news-popup" v-if="showModal">
            <div class="news-popup">
              <div class="overlay"></div>
              <div class="news-popup__content">
                <div class="news-popup__content__close" @click="showModal = false"></div>
                <div class="news-popup__content__top">
                  <div class="news-popup__content__top__left" style="background-image:url(../../../../static/img/car.jpg)"></div>
                  <div class="news-popup__content__top__right">
                    <div class="news-popup__content__title">
                      <slot name="title"></slot>
                    </div>
                  <div class="news-popup__content__top__bottom">
                    <span class="news-popup__content__top__bottom__date">
                      <slot name="date"></slot>
                    </span>
                    <span class="news-block__label">Рейтинги</span>
                  </div>
                  </div>
                </div>
                <div class="news-popup__content__bottom">
                  <p class="news-popup__content__bottom__p">
                    <slot name="text"></slot>
                  </p>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="news-wrap__bottom">
      <div class="news-wrap__bottom__arrows">
        <div class="news-wrap__bottom__arrow news-wrap__bottom__arrow_left"></div>
        <div class="news-wrap__bottom__arrow news-wrap__bottom__arrow_right"></div><span class="news-wrap__bottom__arrows__count">Показано 20 из 73</span>
      </div>
      <el-pagination
        layout="prev, pager, next"
        :total="1000">
      </el-pagination>
    </div>
  </div>
</template>

<template>
  <div class="main">
    <popup v-for="(news, index) in news" :key="index">
      <div slot="title"> {{ news.title }} </div>
      <div slot="date"> {{ news.date }} </div>
      <div slot="text"> {{ news.text }} </div>
    </popup>
  </div>
</template>

and now some data comes to the component, I pass it through the slot.
but I can't display slot name="same name" both in the record and in the modal, what should I do in such a situation?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
londhor, 2019-12-27
@londhor

you can transfer data through prefixes.
pContent for post and mContent for modal

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question