K
K
KushchO2019-03-20 20:49:30
JavaScript
KushchO, 2019-03-20 20:49:30

How to stop recursive function from executing when url vue.js is entered?

Good afternoon!
There is a worker function that recursively switches the states of components. Tell me how to stop its execution if the user enters one of the three available addresses. The function should be continued based on the address entered.
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()
  }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question