LoginSignup
5

More than 3 years have passed since last update.

posted at

updated at

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

エラー内容

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: {
  },
}

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
What you can do with signing up
5