1
0

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 3 years have passed since last update.

【vue.js】TypeError: Cannot read property 'xxxx' of undefined

Posted at

下記のエラーが出ています!

628 [Vue warn]: Error in v-on handler: "TypeError: Cannot read property 'index' of undefined"
Cannot read property 'index' of undefined

原因: DOM はまだ更新されないです!!!!!!

解決方法: 「$nextTick」を使えばokです!

callback の実行を遅延し、DOM の更新サイクル後に実行します。DOM の更新を待ち受けるためにいくつかのデータを更新した直後に使用してください。callback の this コンテキストは自動的にこのメソッドを呼びだすインスタンスに束縛されることを除いて、グローバルな Vue.nextTick と同じです。

index.vue
methods:{
    click(){
     // DOM はまだ更新されない
        this.$nextTick(function(){
       // DOM が更新された
            console.log()
        });
    }
}

参考:
API-Vue.nextTick( [callback, context] )

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?