Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

Vue.jsでクリックイベントを2つ持たせる方法

More than 3 years have passed since last update.

Vue.jsでクリックイベントを2つ持たせる方法

単純にクリックイベントに2つ書けばいけます。

v-on:click="click_1(); click_2()"
@click="click_1(); click_2()"

あんまり使わないとは思いますが、検索で出てこなかったので書いておきます。

その他

動作サンプル

https://ykhirao.github.io/qiita/click_vuejs/

ソースコード

最新版

<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <script src="https://unpkg.com/vue@2.5.3/dist/vue.js"></script>
  <title>Vue.js</title>
  <style>
    p {
      padding: 2em;
      width: 200px;
      border: solid;
    }
    p:hover {
      border-color: #6C9BD2;
      color: #6C9BD2;
    }
  </style>
</head>
<body>
  <div id='demo'>
    <p v-on:click="click_1(); click_2()">クリックイベントはこちら</p>
    <ul v-for="text in list">
      <li>{{text}}</li>
    </ul>
  </div>
  <script>
    new Vue({
      el: '#demo',
      data: {
        list: []
      },
      methods: {
        click_1: function() {
          this.list.push("by click 1")
        },
        click_2: function() {
          this.list.push("by click 2")
        }
      }
    })
  </script>
</body>
</html>

ykhirao
Web Developer For 4 years. PHP/Laravel && (React OR Vue.js)
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away