[Vuejs]-Fetch promise not defined even when console.log shows the value

0👍

name and price belong to a different scope. To pass it to next chain in .then, you need to return the value

static insertPost(shareName) {
  axios.get(url)
    .then(res => {
      const name = res.data['Meta Data']['2.Symbol']
      console.log(res.data['Time Series (15min)']['2019-08-02 15:45:00']['1.open']);
      const price = res.data['Time Series (15min)']['2019-08-02 15:45:00']['1. open'];
      return { name, price }
    })
    .then(res => {
      return axios.post(url, {
        name: res.name,
        price: res.price
      })
    });
}

Leave a comment