Thanks @twestrick It makes perfect sense, but it seems like I’m still missing something, may be you can identify the issue in this code that prevents me using loadingController.
import {
IonItem,
IonLabel,
IonList,
IonButton,
IonThumbnail,
IonText,
loadingController,
} from "@ionic/vue";
import { defineComponent, ref } from "vue";
import contentService from "../providers/contentService";
import { Splide, SplideSlide } from "@splidejs/vue-splide";
import "@splidejs/vue-splide/css";
import ListItem from "@/components/list/ListItem.vue";
import MyFavoriteTopBar from "@/components/frontpage/MyFavoriteTopBar.vue";
export default defineComponent({
name: "FrontPageComponent",
components: {
Splide,
SplideSlide,
IonItem,
IonLabel,
IonList,
IonButton,
IonThumbnail,
IonText,
ListItem,
MyFavoriteTopBar,
},
setup() {
const { fetchArticles, contentList } = contentService();
const selectedSubFilter = ref("latest");
const subFilters = ref({
...
});
const options = ref({
rewind: true,
autoplay: true,
perPage: 2,
perMove: 2,
gap: "0.3rem",
arrows: false,
pagination: false,
});
/* can't use async method in setup()
const async filterNews */
const filterNews = (subFilter: object, index: string) => {
selectedSubFilter.value = index;
let loading = await showLoader();
fetchArticles(subFilter.tags);
loading.dismiss();
};
async function showLoader(
cssClass = "loading-custom-class",
message = "Please wait...",
duration = 0,
translucent = false,
backdropDismiss = false,
spinner: any,
id: "login"
): Promise<void> {
const loading = await loadingController.create({
cssClass,
message,
translucent,
backdropDismiss,
spinner,
duration,
id,
// keyboardClose: true
});
// Show loader
console.log("show loader");
return await loading.present();
}
return {
// Methods
filterNews,
contentList,
// formatContentDate,
options,
subFilters,
selectedSubFilter,
};
},
});
</script>
<template>
<MyFavoriteTopBar></MyFavoriteTopBar>
<div class="filters">
<ion-button
v-for="(subFilter, index) in subFilters"
:key="subFilter"
:color="selectedSubFilter == index ? 'primary' : 'light'"
@click="filterNews(subFilter, index)"
>
{{ subFilter.title }}
</ion-button>
</div>
<ion-list class="article-list">
<ListItem
v-for="data in contentList"
:key="data.content.id"
:data="{
id: data.content.id,
name: data.content.name,
feature_name: data.article.feature_name,
picture_url: data.article.picture_url,
}"
>
</ListItem>
</ion-list>
</template>