【Vue.js】v-forの完了後のイベント定義
ポイント
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>
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>
Author And Source
この問題について(【Vue.js】v-forの完了後のイベント定義), 我々は、より多くの情報をここで見つけました https://qiita.com/SFITB/items/ce58b621c206ac47809a著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .