VueJs: method 内で setTimeout を使い setTimeout 内で他に定義した method を呼び出す方法

methods: {

  testFunc() {
     console.log('OK');

  }

},

mounted() {
  setTimeout(function(){

    this.testFunc();  // エラー

  }, 1000);

}  

 

this.testFunc() だとエラー。以下に訂正

mounted() {

  var self = this;
  setTimeout(function(){

    self.testFunc();  // OK

  }, 1000);

}

 

参考:

stackoverflow.com