23
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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)
    }
  }
})

これでいけました。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?