| import { ref, watch } from 'vue@next'; | |
| export default { | |
| setup() { | |
| const hasLoaded = ref(false); | |
| const books = ref([]); | |
| watch(hasLoaded, (value) => { | |
| if (value) { | |
| fetchBooks(); | |
| } | |
| }); | |
| const fetchBooks = async () => { | |
| const response = await fetch('https://localhost:3000/books'); | |
| const data = await response.json(); | |
| books.value = data; | |
| }; | |
| return { | |
| hasLoaded, | |
| books, | |
| }; | |
| }, | |
| }; |