Last active
February 10, 2021 14:54
-
-
Save hang15/1430d206c2b5f54e2244519df4bee764 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Ref, ref } from "vue"; | |
export function useFetcher(fetcher) { | |
const data = ref(null); | |
const loading = ref(false); | |
const error = ref(null); | |
const getData = async (...params) => { | |
loading.value = true; | |
data.value = null; | |
error.value = null; | |
try { | |
data.value = await fetcher(...params); | |
} catch (err) { | |
error.value = err; | |
} | |
loading.value = false; | |
}; | |
return { | |
data, loading, error, getData, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment