A
A
Alexander2020-05-18 13:25:23
Vue.js
Alexander, 2020-05-18 13:25:23

Unknown error: Cannot read property 'get' of undefined?

Hello, I encountered this error: 5ec261f78ce8b506704702.png

Code:

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)
})


This is how I use it in 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)
      })
    }
}


I would be very grateful for any help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor, 2020-05-18
@AlexVue

Why does no one ever read the bugs? Since when is TypeError an unknown error? This is a type error, the variable is not of the expected type. undefined is a separate type in JS

TypeError: Cannot read property 'get' of undefined.
TypeError: Cannot read property 'get' because it is not defined.

Next is the call stack. Walk the stack and find the error.
PS There are 5 files in the stack, why did you only post 3? Why main.js, API.js and Store.js if the error occurs in other files?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question