[Vuejs]-Counter not increment in vue.js

2👍

You need to use a Number instead of a String for 0 See jsfiddle here.

HTML

<div id="react">
  <button @click="counter += 5">Increment</button>
  <p>{{ result }}</p>
</div>

JS

new Vue({
  el: '#react',
  data: {
    counter: 0
  },
  computed: {
    result: function() {
      return this.counter;
    }
  }
})

0👍

counter is defined with ‘0’(String) instead of 0(number).

You also don’t need the computed value to show the result.

Only {{counter}} would be enough.

Leave a comment