Last active
August 24, 2022 12:42
-
-
Save letswritetw/ccc90625606ba1d83941e4ce5c6be385 to your computer and use it in GitHub Desktop.
vue3-composition-api-import
This file contains 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 } from 'vue' | |
export default function(uri) { | |
const data = ref(null); | |
const getData = async () => { | |
try { | |
const result = await fetch(uri); | |
if(!result.ok) { | |
throw Error('fetch data 失敗'); | |
} | |
data.value = await result.json(); | |
} catch(error) { | |
throw Error(error) | |
} | |
} | |
return { data, getData } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment