LoginSignup
0
0

More than 1 year has passed since last update.

V-onディレクティブを動的に表現

Last updated at Posted at 2021-05-05
<body>
  <script src="https://cdn.jsdelivr.net/npm/vue@2.6.12/dist/vue.js"></script>
  <div id="app">
     <p>現在{{ number }}回クリックされています</p>
     <button v-on:[event]=countUp>カウントアップ</button>>
</div>
<script>
  new Vue({
    el: '#app',
    data: {
      number: 0,
      event: 'click'
    },
    methods: {
      countUp: function() {
        this.number += 1;
      }
    }
  })
</script>
</body>

20210505-130744.png

省略記法1
<button @[event]=countUp>カウントアップ</button>>
省略記法2
<button @click=countUp>カウントアップ</button>>
    data: {
      number: 0,
      event: 'click'
    },

データ内のevent: 'click'は消してください。

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