LoginSignup
22
22

More than 5 years have passed since last update.

vue.jsのv-forで選択された情報を取得して何かしたい

Last updated at Posted at 2017-08-27

こんな時どうする?

例えばv-forでテーブルを作成した際に、選択されたレコードの情報を使って何かしたい

やりかた

オブジェクトでの例

・・・

<table>
  <tbody>
    <tr v-for="item in items" @click="select(item.name)">
      <td>{{ item.name }}</td>
    </tr>
  </tbody>
</table>

・・・
new Vue({
  data: {
    items: [{name: 'hoge'}, {name: 'fuga'}, ・・・]
  },
  method: {
    select: function (itemname) {
      alert(itemname)
    }
  }
})

これでいけました。

22
22
1

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
22
22