21
6

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.

Nuxt.jsとaxiosでエラーTypeError: Cannot read property '$get' of undefined

Last updated at Posted at 2019-03-14

エラー内容

TypeError: Cannot read property '$get' of undefined

Nuxt.jsでaxiosを導入したのに…何で!?

導入手順

  1. npm install --save @nuxtjs/axiosでaxiosをインストール
  2. nuxt.config.jsの設定ファイルを編集
  3. async, await, $axios.$getなどで使える!

エラー原因

2.nuxt.config.jsの設定ファイルを編集

原因は**「設定ファイルの追記をしていない」もしくは「デフォルトの記述より上に書かれている」**でした。

どれだけアホなミスなんでしょうか…笑

nuxt.config.js
import pkg from './package'

export default {
  mode: 'universal',

  // デフォルトで色々書いてる

  // ↓↓↓ デフォルトの末尾に追記 ↓↓↓
  modules: [
    '@nuxtjs/axios',
  ],
  axios: {
  },
}
21
6
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
21
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?