Vue.js get current year


We can use current date time object to get the current year. Here in this tutorial, we are going to explain how you can use can get current year in vue.js. You can also use our online editor to edit and run the code online.


Vue.js get current year Example

You can get current year in vue.js simply as below-

Example:

<div id="app">	
	<p>Current Year = {{currentYear}}</p>
	<button @click="myFunction()">Click Me</button>
</div>
<script>
 new Vue({
el: '#app',
  
  data: { 
	  currentYear:''
  },
  
   methods:{
    myFunction: function () {	
		this.currentYear = (new Date()).getFullYear();
    }
   }

});
</script>       

Try it »

Output of above example-

Vue.js get current year

Advertisements

Add Comment

📖 Read More