vue.js-計數器

20201029

by YiruAtStudio

HTML

<div id="myapp">
      <button v-on:click="fn()">+1</button><br>
      <button @click="fn2()">-1</button><br>
      計數:{{num}}
    </div>

JavaScript

var myapp = new Vue({
  el: '#myapp',
  data: {
    num: 0
  },
  methods: {
    fn: function () {
      this.num += 1
    },
    fn2: function () {
      this.num -= 1
    }
  }
})