You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

16 lines
589 B

// 全局「处理中」遮罩状态:引用计数(支持并发请求叠加),>0 即显示遮罩。
// 与 useToast 同样用 Nuxt useState 做 SSR 安全的全局共享状态。
// begin()/end() 成对调用(见 useApi 对写操作的包装),end 取 max(0, n-1) 防计数为负。
export function useLoading() {
const count = useState<number>('app:loading', () => 0)
const loading = computed(() => count.value > 0)
function begin() {
count.value++
}
function end() {
count.value = Math.max(0, count.value - 1)
}
return { count, loading, begin, end }
}