added validation when adding a book

This commit is contained in:
2025-09-24 17:06:39 +02:00
parent 8432902df1
commit 2f0a9b5127
7 changed files with 105 additions and 13 deletions

View File

@@ -3,13 +3,13 @@ import { ref } from 'vue'
const baseUrl = "http://localhost:8080"
function useFetch(url) {
const data = ref(null)
const error = ref(null)
const data = ref(null);
const error = ref(null);
fetch(url)
.then((res) => res.json())
.then((json) => (data.value = json))
.catch((err) => (error.value = err))
.catch((err) => (error.value = err));
return { data, error }
}
@@ -19,11 +19,11 @@ export function getBooks() {
}
export function postBook(book) {
fetch(baseUrl + '/book', {
return fetch(baseUrl + '/book', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(book.value)
});
})
}