Skip to content
Advertisement

Problems with my API in Vue.js with axios

I’m creating a bookstore app with Vue.js. The books are in this API https://api.myjson.com/bins/1h3vb3, but I can’t show them in my HTML with the following function and I don’t understand why:

JavaScript
JavaScript

Advertisement

Answer

axios.get resolves to a Response, which stores the received data in the data property. In your code, you’ve incorrectly set this.books to response, which is the entire Response object. You should instead reference response.data.books:

JavaScript

Also, to render a list of items, use v-for="book in books" like this:

JavaScript

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement