Skip to content

Commit

Permalink
Use axios instead of fetch
Browse files Browse the repository at this point in the history
Co-authored-by: TheoThmn <s0586704@htw-berlin.de>
  • Loading branch information
ZieglerAaron and TheoThmn committed Jan 7, 2024
1 parent a4e5e31 commit 43e7df8
Showing 1 changed file with 16 additions and 31 deletions.
47 changes: 16 additions & 31 deletions src/components/MyCamerasList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -309,43 +309,28 @@ const cameras: Ref<Camera[]> = ref([])
const stocks: Ref<Stock[]> = ref([])
const searchField: Ref<string> = 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(() => {
Expand Down

0 comments on commit 43e7df8

Please sign in to comment.