11
1

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

[Vue2.0] TypeError: Cannot read property '$createElement' of undefined

Posted at

Vueで遭遇した事象を共有。

事象

以下のようにHogeページを追加し、該当ページに遷移しようとしてrouter.push('/hoge')したところ、エラー発生

router/index.js
...
    {
      path: '/hoge',
      name: 'hoge',
      components: Hoge
    },
...
> TypeError: Cannot read property 'loadItems' of undefined

該当のページでは

Hoge.vue
mounted () {
  this.loadItems()
},
methods: {
  loadItems () {
    //.....
  }
}

としていたので

Hoge.vue
mounted () {
  console.log(this)
  this.loadItems()
},

this がundefined。
this汚染やっちまった?と思い、探してみたがハズレ。
mounted をコメントアウトしてみると、次のエラーが発生

>TypeError: Cannot read property '$createElement' of undefined

原因と答え

stackoverflowに答えが...
https://stackoverflow.com/questions/50218836/vue-router-typeerror-cannot-read-property-createelement-of-undefined?rq=1

誤:components
正:component

router/index.js
...
    {
      path: '/hoge',
      name: 'hoge',
      component: Hoge
    },
...

上記とすると直りました。

環境

Vue2.0 + vuex

11
1
1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?