Как l oop функция в VueJs методы? - PullRequest
0 голосов
/ 01 мая 2020

Я хочу l oop этот метод, чтобы у меня была карусель, которая не прекращает изменять изображение и связанный текст. Вот метод:

mounted() {
    this.rotateImage()
  },
  methods: {
    rotateImage() {
      setTimeout(() => this.rotateImage(), 5000) // call this function again in 5 seconds (recursive)
      setTimeout(() => this.$refs.container.changeImage(), 1500) // after 1.5s, begin image transition
      this.$refs.overlay.changeText()
    }
  }

1 Ответ

0 голосов
/ 02 мая 2020

Просто сбросьте currentIndex на 1, когда он достигнет последнего элемента этого массива

ImageContainer. vue

changeImage() {
  if (this.currentIndex === this.images.length - 1) 
    this.currentIndex = 1;
  else this.currentIndex += 1;
}

TextOverlay. vue

changeText() {
  if (this.currentIndex === this.texts.length - 1) 
    this.currentIndex = 1;
  else this.currentIndex += 1;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...