A
A
Alexander Florenko2019-02-23 18:56:47
JavaScript
Alexander Florenko, 2019-02-23 18:56:47

Why is there an error in the async function?

Hello.
I set up vue cli + ssr
Everything seemed to be fine, but for some reason the async / await function does not work.
Sample code below

// начинается все с axios

import axios from 'axios';

export default () => {
  return axios.create({
    baseURL: '',
    headers: {'X-Requested-With': 'XMLHttpRequest'}
  })
}

//тут запрос для тестов 
import Api from './index';

export default {
  getInfo () {
    return Api.get('https://api.coindesk.com/v1/bpi/currentprice.json')
  }
}

//тут store, все операции с апи 
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex);

import Api from "../API/default"

export function createStore () {
  return new Vuex.Store({
    state: {
      items: {
        
      }
    },
    actions: {
      async getItems({commit}) {
        const RES = await Api.getInfo();
        commit('updateItems', RES.data)
      }
    },
    mutations: {
      updateItems: (state, val) => 
          state.items = val
    }
  })
}

As a result, I get this error in the console
TypeError: _index__WEBPACK_IMPORTED_MODULE_0__.default.get is not a function

What could be the problem?
How to decide?
If any additional information is needed, I'll post it.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey Yarkov, 2019-02-23
@SkipTyler

What if Api().get?

Y
Yuri Esin, 2019-02-23
@Exomode

//here is a request for tests
import Api from './index';
export default {
getInfo () {
return Api.get(' https://api.coindesk.com/v1/bpi/currentprice.json ')
}
}

so where is the get() method itself? it's just getInfo()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question