26 lines
536 B
TypeScript
26 lines
536 B
TypeScript
import api from '@/utils/api.ts';
|
|
import { defineStore } from 'pinia';
|
|
import { onMounted, ref } from 'vue';
|
|
|
|
export const useCarsStore = defineStore('cars', () => {
|
|
const cars = ref([]);
|
|
const showLoader = ref(false);
|
|
|
|
onMounted(async () => {
|
|
try {
|
|
showLoader.value = true;
|
|
const response = await api.get(`/cars.json`);
|
|
cars.value = Object.values(response.data)
|
|
} catch (e) {
|
|
console.log(e);
|
|
} finally {
|
|
showLoader.value = false;
|
|
}
|
|
});
|
|
|
|
return {
|
|
cars,
|
|
showLoader,
|
|
}
|
|
})
|