feat 搭建架构骨架
This commit is contained in:
21
src/composables/useLoading.ts
Normal file
21
src/composables/useLoading.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { ref, type Ref } from 'vue'
|
||||
|
||||
/** 请求 loading 状态管理 */
|
||||
export function useLoading(initial = false): {
|
||||
loading: Ref<boolean>
|
||||
withLoading: <T>(fn: () => Promise<T>) => Promise<T>
|
||||
} {
|
||||
const loading = ref(initial)
|
||||
|
||||
async function withLoading<T>(fn: () => Promise<T>): Promise<T> {
|
||||
loading.value = true
|
||||
try {
|
||||
return await fn()
|
||||
}
|
||||
finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
return { loading, withLoading }
|
||||
}
|
||||
Reference in New Issue
Block a user