From 43e7df8bec3add1a9426c92c18f9a186a2de4b11 Mon Sep 17 00:00:00 2001 From: ZieglerAaron Date: Sun, 7 Jan 2024 18:08:16 +0100 Subject: [PATCH] Use axios instead of fetch Co-authored-by: TheoThmn --- src/components/MyCamerasList.vue | 47 +++++++++++--------------------- 1 file changed, 16 insertions(+), 31 deletions(-) diff --git a/src/components/MyCamerasList.vue b/src/components/MyCamerasList.vue index 307c34a..bfe0f15 100644 --- a/src/components/MyCamerasList.vue +++ b/src/components/MyCamerasList.vue @@ -309,43 +309,28 @@ const cameras: Ref = ref([]) const stocks: Ref = ref([]) const searchField: Ref = ref('') -function loadCameras() { +async function loadCameras() { const baseUrl = import.meta.env.VITE_BACKEND_BASE_URL const endpoint = baseUrl + '/cameramodel' - const requestOptions: RequestInit = { - method: 'GET', - redirect: 'follow' - } - fetch(endpoint, requestOptions) - .then(response => response.json()) - .then( - result => { - result.forEach( - (cameramodel: Camera) => { - console.log(cameramodel) - cameras.value.push(cameramodel) - } - ) - } - ) - .catch(error => console.log('error', error)) + const response: AxiosResponse = await axios.get(endpoint); + const responseData: Camera[] = response.data; + responseData.forEach( + (cameramodel: Camera) => { + cameras.value.push(cameramodel) + } + ) } -function loadStocks() { +async function loadStocks() { const baseUrl = import.meta.env.VITE_BACKEND_BASE_URL const endpoint = baseUrl + '/stocks' - const requestOptions: RequestInit = { - method: 'GET', - redirect: 'follow' - } - fetch(endpoint, requestOptions) - .then(response => response.json()) - .then(result => { - result.forEach((stock: Stock) => { - stocks.value.push(stock) - }) - }) - .catch(error => console.log('error', error)) + const response: AxiosResponse = await axios.get(endpoint); + const responseData: Stock[] = response.data; + responseData.forEach( + (stock: Stock) => { + stocks.value.push(stock) + } + ) } onMounted(() => {