1
2

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.

VueJSの'Uncaught TypeError: Cannot read property 'apply' of undefined'を解決する。

Posted at

背景

v-onでmethodを動作させる以下のようなmethodを書いていたら

<template>
<div>
  <button v-on:click="submitMethod">
</div>
</template>

<script>
export default {
    name: "Component",
    method: {
        submitMethod: function(){
           // 何かの動作を記述。
        }
    },
    // その他コード
}

</script>


以下のエラーでよく詰まったので解決法をメモする。

'Uncaught TypeError: Cannot read property 'apply' of undefined'

解決法

理由の多くは、「関数が定義されてない」ということが多い。
ただ、「いや、タイポもないはず!!」という人は以下のようになってることが多い。

// ダメな方
method: {
  submitMethod: function(){
    ...
  }
}

// 動く方
methods: {
  submitMethod: function(){
    ...
  }
}

そうmethodsが正しいのに、methodになってしまっている。
vueは、このエラーを実行時にしか教えてくれない。
しかもエラー文もUncaught TypeError: Cannot read property 'apply' of undefined
と全く関係なさげなメッセージである。

他の人も気をつけてね。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?