Неизвестная ошибка: Cannot read property 'get' of undefined?

Здравствуйте, столкнулся с такой ошибкой: 5ec261f78ce8b506704702.png

Код:

main.js:
import API from './services/Api.js'

API.interceptors.response.use(
  response => {
    if (response.data instanceof Blob) {
      return response.data
    }
    return response.data.data || {}
  },
  error => {
    if (error.response) {
      Vue.prototype.$buefy.toast.open({
        message: error.response.data.message || 'Something went wrong',
        type: 'is-danger'
      })
    } else {
      Vue.prototype.$buefy.toast.open({
        message: 'Unable to connect to server',
        type: 'is-danger'
      })
    }
    return Promise.reject(error)
  }
)

Vue.prototype.$http = API


API.js:
import axios from 'axios'
import { cacheAdapterEnhancer } from 'axios-extensions'

export default axios.create({
  baseURL: 'http://api.ivinete.loc/method/',
  headers: { 'Cache-Control': 'no-cache' },
  // cache will be enabled by default
  adapter: cacheAdapterEnhancer(axios.defaults.adapter)
})


Вот так применяю его в Store.js
actions: {
    login ({commit}, user) {
      return new Promise((resolve, reject) => {
        commit('clearError')
        commit('setLoading', true)

        const data = this.$http.get('oauth.login', { params: user })
        console.log(data)
      })
    }
}


Буду очень благодарен любой помощи.
  • Вопрос задан
  • 3495 просмотров
Решения вопроса 1
@loonny
Почему никто и никогда не читает ошибки? С каких пор TypeError это неизвестная ошибка? Это ошибка типа, переменная имеет значение не того типа который ожидается. undefined - это отдельный тип в JS

TypeError: Cannot read property 'get' of undefined.
Ошибка типа: Невозможно прочитать свойство 'get' так как оно не определено.

Дальше стек вызовов. Пройдитесь по стеку и найдете ошибку.

P.S. В стеке 5 файлов, почему вы только 3 выложили? Почему именно main.js, API.js и Store.js, если ошибка возникает в других файлах?
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы