@KushchO

Как остановить выполнение рекурсивной функции при вводе url vue.js?

Добрый день!
Есть рабочая функция , которая рекурсивно переключает состояния компонентов. Подскажите, как остановить ее выполнение если пользователь введет один из трех доступных адресов. Работу функции нужно продолжить на основе введенного адреса.

https://github.com/KushchO/traffic_lights/blob/mas...

created () {
    const tf = this
    let isStart = true
    const startLight = function () {
      setTimeout(() => {
        const routes = tf.$router.options.routes
        console.log(tf.traffTimeout[tf.routeIndex])
        // Цвет светофора в зависимотси от this.routes[this.routeIndex].path. Таймер выставляю тоже отнасительно this.routeIndex
        routes[tf.routeIndex].path === '' ? tf.colorRed = 'red' : tf.colorRed = 'grey'
        routes[tf.routeIndex].path === '/1' ? tf.colorYellow = 'yellow' : tf.colorYellow = 'grey'
        routes[tf.routeIndex].path === '/2' ? tf.colorGreen = 'green' : tf.colorGreen = 'grey'
        tf.$router.push(routes[tf.routeIndex])
        tf.routeIndex = (tf.routeIndex + 1) % routes.length
        startLight()
      }, isStart ? 100 : tf.traffTimeout[tf.routeIndex])
      isStart = false
    }
    startLight()
  }
  • Вопрос задан
  • 399 просмотров
Пригласить эксперта
Ваш ответ на вопрос

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

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