serii81
@serii81
Я люблю phр...

Почему не срабатывает аниимация при появлении элемента в списке?

Добрый день.
Сделал слайдер на vue js.
При клике на стрелки, показывается элемент, у которого index в массиве равен currentSlide.
<transition-group tag="div" class="single-estate-planimetry__slider" name="planslider" appear>
    <div v-if="index === currentPlanimetry"  :data-index="index" class="single-estate__descr-img" v-for="(item, index) in planimetry" :key="item.nome">
        <img :src="item.nome" :alt="item.title">
    </div>
</transition-group>

const appSingle = new Vue({
    el: "#app-single",
    data() {
      return {
        planimetry: [],
        currentPlanimetry: 0
      }
    },
methods: {
      prevPlanimetry(){
        if (this.currentPlanimetry === 0) {
          this.currentPlanimetry = this.planimetry.length - 1
        } else {
          this.currentPlanimetry--
        }
      },
      nextPlanimetry(){
        if (this.currentPlanimetry === this.planimetry.length - 1) {
          this.currentPlanimetry = 0
        } else {
          this.currentPlanimetry++
        }
      },
}
});


.planslider-enter-from {
  opacity: 0;
}
.planslider-enter-to {
  opacity: 1;
}
.planslider-enter-active {
  transition: all 3s;
}

.planslider-leave-from {
  opacity: 1;
}
.planslider-leave-to {
  opacity: 0;
}
.planslider-leave-active {
  //transition: all 3s;
}

Вот при исчезновении работает, а при появлении, нет.

Почему?
  • Вопрос задан
  • 52 просмотра
Решения вопроса 1
0xD34F
@0xD34F Куратор тега Vue.js
Судя по

const appSingle = new Vue({

вы используете vue 2. В то время как имена классов соответствуют третьей версии (был ряд изменений):

.planslider-enter-from {

.planslider-leave-from {


Непосредственно к заявленной проблеме не относится, но мимо пройти никак нельзя:

<transition-group tag="div" class="single-estate-planimetry__slider" name="planslider" appear>
    <div v-if="index === currentPlanimetry"  :data-index="index" class="single-estate__descr-img" v-for="(item, index) in planimetry" :key="item.nome">

Заменить transition-group на transition. Убрать v-if и v-for. Сделать вычисляемое свойство, представляющее текущий элемент.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы