Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140762

Output Multiple Li's with Axios Get Api [duplicate]

$
0
0

I am trying to output an ordered list using axios get and update that call every 60 seconds. However, I am unable to figure out how to output more than one item using a template literal. Only the last item in the array is outputting to HTML. How do I output all items in the array to the ordered list.

https://codepen.io/zepzia/pen/YzPMLLK

<ol id="list"></ol>

const apiOne = 'https://jsonplaceholder.typicode.com/posts';
const list = document.querySelector('#list');

const apiCall = () => {
  axios.get(apiOne)
    .then(resp => {
      resp.data.forEach(item => {
        let output = `<li class="item">${item.title} - ${item.id}</li>`;

        list.innerHTML = output;
      })
    })
}

apiCall();
setInterval(() => apiCall(), 60000)

Viewing all articles
Browse latest Browse all 140762

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>