Vue.js 2 template

by Edward Tanguay

HTML

<script src="https://unpkg.com/[email protected]/dist/vue.js"></script>

<div id="app">
  <div>
  {{total}}
  </div>
  <the-counter></the-counter>
  <the-counter></the-counter>
  <the-counter></the-counter>
  
</div>

JavaScript

Vue.component('the-counter', {
	template: '<button @click="incrementCounter()">{{counter}}</button>',
  data: function() {
  	return {
    	counter: 4
    }
  },
  methods: {
    incrementCounter: function() {
      this.counter++;
      this.$emit('increment');
    }
  }
});

new Vue({
  el: '#app',
  data: {
  	total: 0
  },
  methods: {
  	incrementMainCounter: function() {
    	$this.counter++;
    }
  }
});