vue timer refresh data in real time

<script> 
  export default { 
    data () { 
      return { 
        list: []   // List of acquired data 
      } 
    } 
    created () { 
      this .getData () 
    } 
    methods: { 
      // This is the function to get data 
      getData () { 
        . .... 
      } 
      // This is a timer 
      timer () {
         return setTimeout (() => {
           this .getData () 
        }, 5000 ) 
      } 
    }, 
    watch: { 
      list () { 
      this  .timer ()
      }
    }
    destroyed() {
  clearTimeout(this.timer)
    }
  }
</script>

 

Guess you like

Origin www.cnblogs.com/aknife/p/12677757.html
Recommended