LoginSignup
2
0

More than 3 years have passed since last update.

【Vue.js】v-forの完了後のイベント定義

Last updated at Posted at 2019-07-19

ポイント

DOMの更新後にイベントを実行する。

▶ 公式リファレンス:Vue.nextTick( [callback, context] )

nexttick.js

this.$nextTick(() => {
       //処理
});

v-for.vue

<template>
<!-- v-forでリスト作成 -->
<ul>
  <li v-for=" item in items">{{ item }}</li>
</ul>
</template>

<script>
export default {
  data() {
    return {
       items: []
    }
  },
  mounted() {
    for(let i = 0 ; i <= 5 ; i++) {
       this.items.push(i);
    }
    //--- ※v-for完了イベント
    this.$nextTick(() => {
       alert('done');
     });
  }
}
</script>

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