Promise not returning value

2

My request is returning this:

data: Promise

Opening Developer Tools from Chrome I see this:

data: Promise
__proto__:Promise
[[PromiseStatus]]:"resolved"
[[PromiseValue]]:"24/01/2016"

Using the axios, how can you print this value?

  Lista (url) {
    axios.get(url)
    .then(res => res.data)
    .then(res => this.publicacaoList = res.map( (contato) => ({
      data: axios.get(contato.id_url).then(res => res.data.data_registro).catch(e => console.log(e)),
      email: contato.email,
      tel: contato.tel
    }) )   )
    .catch(e => {
      console.log(e)
    })
  }

Where contact.id_url is a url where I request to fetch the date. The fields of the email and tel table return normally, the date field returns an empty object {}

    
asked by anonymous 06.10.2017 / 18:48

1 answer

2

When you do data: axios.get(contato.id_url) this var returns a promise to data , and what you want is the value of that ajax. Then you have to solve this ajax (s) first and then set data .

Suggestion:

Lista(url) {
  axios.get(url)
    .then(res => {
      const futureData = res.data.map(contato => axios.get(contato.id_url));
      return Promise.all(futureData).then(contactos =>
        this.publicacaoList = contactos.map((data, i) => ({
            data: data,
            email: res.data[i].email,
            tel: res.data[i].tel
          });
        });
    });
  .catch(e => {
    console.log(e)
  })
}
    
06.10.2017 / 21:49