23 lines
712 B
JavaScript
23 lines
712 B
JavaScript
import { defineStore } from "pinia";
|
|
import { ref, computed } from "vue";
|
|
|
|
export const useLoadingStore = defineStore("loading", () => {
|
|
const loadingCount = ref(0); // 요청 개수를 추적
|
|
|
|
const startLoading = () => {
|
|
loadingCount.value++;
|
|
};
|
|
|
|
const stopLoading = () => {
|
|
if (loadingCount.value > 0) {
|
|
setTimeout(() => {
|
|
loadingCount.value--;
|
|
}, 200); // 약간의 지연을 추가하여 응답이 동시에 도착해도 안정적으로 감소
|
|
}
|
|
};
|
|
|
|
const isLoading = computed(() => loadingCount.value > 0); // 하나라도 요청이 있으면 로딩 활성화
|
|
|
|
return { isLoading, startLoading, stopLoading };
|
|
});
|