| 12345678910111213141516171819202122232425 |
- export const useLoading = () => {
- const isLoading = ref(false)
- const loadingMessage = ref('')
-
- const setLoading = (loading, message = '처리 중...') => {
- isLoading.value = loading
- loadingMessage.value = message
- }
-
- const withLoading = async (asyncFn, message = '처리 중...') => {
- try {
- setLoading(true, message)
- return await asyncFn()
- } finally {
- setLoading(false)
- }
- }
-
- return {
- isLoading: readonly(isLoading),
- loadingMessage: readonly(loadingMessage),
- setLoading,
- withLoading
- }
- }
|