Vue js and Axios does not identify API JSON response

0


// Get Pipelines
const getPipelines = new Vue({
    el: '#top-pipelines',
    data: {
        pipelines: []
    },
    mounted() {
        axios({
            method: 'post',
            url: 'http:..xpto.../getpipelines',
            data: {
                orgId: "ORGIDXPTO",
                pipelineId: "19",
                dateFrom: "2017-11-01",
                dateTo: "2017-11-31"
            }
        })
        .then(function (response) {
               console.log(response);
               this.pipelines = response.json;
        })
    }
});

I also tried "this.pipelines = response.data;"

It's important to say that my answer JSON does not have a header line before the array of objects (see below).


[
    {
        "id_pipeline": "NOME_PIPELINE_XPTO",
        "id_org": "ORGIDXPTO",
        "name": "Nome Pipeline",
        "active": "1"
    },
    {
        "id_pipeline": "NOME_PIPELINE_XPTO",
        "id_org": "ORGIDXPTO",
        "name": "Nome Pipeline",
        "active": "1"
    },
    {
        "id_pipeline": "NOME_PIPELINE_XPTO",
        "id_org": "ORGIDXPTO",
        "name": "Nome Pipeline",
        "active": "1"
    },
    {
        "id_pipeline": "NOME_PIPELINE_XPTO",
        "id_org": "ORGIDXPTO",
        "name": "Nome Pipeline",
        "active": "1"
    },
    {
        "id_pipeline": "NOME_PIPELINE_XPTO",
        "id_org": "ORGIDXPTO",
        "name": "Nome Pipeline",
        "active": "1"
    }
]

Any tips?

    
asked by anonymous 16.01.2018 / 14:37

1 answer

0

You should use

  

response.data

According to the Axios documentation, this is the answer template:

{
  // 'data' is the response that was provided by the server
  data: {},

  // 'status' is the HTTP status code from the server response
  status: 200,

  // 'statusText' is the HTTP status message from the server response
  statusText: 'OK',

  // 'headers' the headers that the server responded with
  // All header names are lower cased
  headers: {},

  // 'config' is the config that was provided to 'axios' for the request
  config: {},

  // 'request' is the request that generated this response
  // It is the last ClientRequest instance in node.js (in redirects)
  // and an XMLHttpRequest instance the browser
  request: {}
}
    
14.09.2018 / 01:41