Vue.js setInterval


Vue.js setInterval– We can use native setInterval in Vue.JS. Here in this tutorial, we are going to explain how to use setInterval function Vue.JS with example and demo.


How to Use setInterval in Vue.JS Example

You can use setInterval function vue.js simply as below-

Example:

<!DOCTYPE html>
<html>
<head>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.13/vue.js"></script>
</head>
<body>
<div id="app">
	 {{message}}
</div>
<script>
 new Vue({
  el: '#app',
  data: {
    message:""
  },
  methods:{
    testFunction: function () {
      var v = this;
      setInterval(function () {
        v.message = new Date().toLocaleTimeString();
    }, 2000);
   }
	},
 mounted () {
  this.testFunction()
}
 });
	
</script>        
</body>
</html>

Try it »

In the above example we have created function testFunction and called setinterval function on mount state. Run the above example and wait for 2 seconds to see the output of interval function.

Output of above example-

Vue.js setInterval Example

Advertisements

Add Comment

📖 Read More