D
D
danilr2019-03-04 20:04:11
JavaScript
danilr, 2019-03-04 20:04:11

Getting public API data via Axios in Vue?

I make a request to a public service through Axios, but an empty object arrives, tell me where is the error?
File with axios object:

import axios from 'axios'

export const HTTP = axios.create({
    baseURL: 'https://frontend-test-case.azurewebsites.net',
    timeout: 10000
})

export const Routes = {
    getList: '/api/report/card',
}

mutation in vuex:
mutations: {
    list(state) {
        HTTP.post(Routes.getList, {
          params: {
              period: 2,
              date: "2019-03-04T15:47:59.784Z"
            }
          })
          .then(data => {
            state.list = data;
            setTimeout(() => {
              console.log(state.list)
            }, 400);
          })
          .catch(error => {
            console.log(error);
          });
      }

Here is a link to the public API:
https://frontend-test-case.azurewebsites.net/swagg...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Yarkov, 2019-04-25
@danilr

Maybe not params, but data? You send POST.
Or so in general (I don’t remember how it’s true in axios:

{
     "period": 0,
     "date": "2019-03-05T15:12:13.319Z"
 }

A
Alex, 2019-03-04
@Kozack

Mutations cannot use asynchronous requests. Mutations are exclusively synchronous. For asynchronous operations, use Actions - which receives data and only then causes a mutation with a prepared object for saving

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question