LoginSignup
0
0

More than 1 year has passed since last update.

[vue]methods

Posted at

methodの使い方

(クリックなどの)イベントをすると発火/実行する

基本的な書き方

<p>{{ counter }}</p>
<!-- v-on:〇〇="メソッド名" -->
<button @click="counterMethod"> *1 </button>

<script>
data: {
  counter: 0,
},
methods: {
  // ↓ counterMethod () { と省略して書ける
  counterMethod: function() {
    this.counter += 1
  }
}
</script>

methodsの追記

htmlに書くときはどちらの書き方でも大丈夫
引数が必要な場合は()必須

ok <button @click="counterMethod"> *1 </button>
ok <button @click="counterMethod()"> *1 </button>
0
0
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
0