VueJs 2.x Computed properties Vs Methods Easiest way Explained

    By: Manu
    4 years ago

    Here is the code used in video

    <!DOCTYPE html>
    <html>
    <head>
    	<title>Vue Project</title>
    	<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
    	<meta content="utf-8" http-equiv="encoding">
    	<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
    	<script type="text/javascript" src="js/vue.js"></script>
    </head>
    <body>
    	<div id="app" class="container">
    		<div class="col-md-6 col-md-offset-3 mb-9" style="margin-bottom:100px;	">
    			
    				<button v-on:click="a++" class='btn btn-primary'>A++ {a}</button>
    				
    				<button v-on:click="b++" class='btn btn-primary'>B++ {b}</button>
    			
    				Changed A = {changeValueA}
    				Changed B = {changeValueB}
    		</div>	
    	</div>
    </body>
    <script type="text/javascript">
    	
    	new Vue({
    		  el:'#app',
    		  data: {
    		  	total:10,
    		  	a:1,
    		  	b:1
    		  },
    		  computed:{
    		  		changeValueA(){
    		 			console.log('changeValueA Fired');
    		 			return this.a+this.total;
    		 		},
    		 		changeValueB(){
    		 			console.log('changeValueB Fired');
    		 			return this.b+this.total;
    		 		}
    		  },
    		  methods:{
    		 		
    		  }
    	});
    
    
    </script>
    </html>
    

    Check Video Here

    https://youtu.be/zHx1F0LvIqU