added validation when adding a book
This commit is contained in:
@@ -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)
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user