LoginSignup
1
0

More than 3 years have passed since last update.

[Vue.js]関数の引数

Last updated at Posted at 2020-11-16

関数に引数を与える

<p>現在{{num}}回クリックされました</p>
//クリックするたび2足される
    <button v-on:click = "countUp(2)">クリック</button>

js
data:{num:0}
methods:{
//これはjsと同じで因数を下の式に当てはめているだけ
      countUp:function(a){
              this.num+=a
                }

関数の引数eventをhtmlに渡す場合

//マウスのX軸とY軸を表示
  <p v-on:mousemove = "mousePosition($event,5)">マウスのX軸とY軸を表示するよ</p>
    <p>x:{{x}}y:{{y}}</p>
data:{x:0,y:0},
methods:{
//マウスの場所xとyに対して渡した数を割る
mousePosition:function(event,divide){
       this.x = event.clientX / divide;
       this.y = event.clientY / divide;
                }

eventをhtmlに渡す場合 $event として渡す

1
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
1
0