Use fetch data component
This commit is contained in:
parent
6cb8267a0b
commit
824fa28126
|
@ -5,7 +5,7 @@ import { useI18n } from 'vue-i18n';
|
|||
import CardList from 'src/components/ui/CardList.vue';
|
||||
import VnImg from 'src/components/ui/VnImg.vue';
|
||||
import VnList from 'src/components/ui/VnList.vue';
|
||||
import FormModel from 'src/components/common/FormModel.vue';
|
||||
import FetchData from 'src/components/common/FetchData.vue';
|
||||
|
||||
import { useAppStore } from 'stores/app';
|
||||
import { storeToRefs } from 'pinia';
|
||||
|
@ -19,20 +19,12 @@ const { openConfirmationModal } = useVnConfirm();
|
|||
const { isHeaderMounted } = storeToRefs(appStore);
|
||||
const { notify } = useNotify();
|
||||
|
||||
const loading = ref(false);
|
||||
const loading = ref(true);
|
||||
const news = ref([]);
|
||||
|
||||
const getNews = async () => {
|
||||
try {
|
||||
loading.value = true;
|
||||
|
||||
const { data } = await api.get('news');
|
||||
news.value = data;
|
||||
} catch (error) {
|
||||
console.error('Error getting news:', error);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
const onFetch = data => {
|
||||
news.value = data;
|
||||
loading.value = false;
|
||||
};
|
||||
|
||||
const deleteNew = async (id, index) => {
|
||||
|
@ -49,6 +41,7 @@ onMounted(async () => getNews());
|
|||
</script>
|
||||
|
||||
<template>
|
||||
<FetchData ref="fetchNewsRef" url="news" auto-load @on-fetch="onFetch" />
|
||||
<Teleport v-if="isHeaderMounted" to="#actions">
|
||||
<QBtn
|
||||
:label="t('addNew')"
|
||||
|
|
Loading…
Reference in New Issue