0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

メソッドに引数を与える ❏Vue.js❏

Posted at

メソッドの引数に与えた数の倍数分カウントアップしていきます!

(例)3を与えるとこうなります。

Screenshot from Gyazo


開発環境はJSFiddle https://qiita.com/ITmanbow/items/9ae48d37aa5b847f1b3b
html
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<div id="app">
  <p>{{ number }}</p>
  <button @click="countUp(3)">カウントアップ</button>
</div>
javascript
new Vue({
  el: "#app",
  data: {
    number: 0
  },
  methods: {
    countUp: function(times) {
      this.number += times;
    }
  }
})

①html側には引数3を与えます。
@click="countUp(3)"

②js側にはtimesとして引数を受け取ります。
countUp: function(times)

③引数分足します
this.number += times;

できあがり!


ではまた!
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?