Vue counter (Without Composition API)

by nolleto

HTML

<body>
  <div id="app">
    <counter-component /> 
  </div>
</body>

CSS

body {
  background: #20262E;
  padding: 20px;
  font-family: Helvetica;
}

#app {
  background: #fff;
  border-radius: 4px;
  padding: 20px;
  transition: all 0.2s;
}

h2 {
  margin-bottom: 8px;
}

Vue

Vue.component('counter-component', {
  data() {
    return {
      counter: 3,
    }
  },
  methods: {
  	increment(){
    	this.counter = this.counter + 1
    },
    
    decrement() {
      this.counter = this.counter - 1
    }
  },
  
  template: `
	<div>
	  <h2>Counter: {{ counter }}</h2>

  	<button @click="increment">Increment</button>
	  <button @click="decrement">Decrement</button>
	</div>
  `
})

new Vue({
	el: "#app",
})