Skip to content

Instantly share code, notes, and snippets.

@letswritetw
Last active August 24, 2022 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save letswritetw/ccc90625606ba1d83941e4ce5c6be385 to your computer and use it in GitHub Desktop.
Save letswritetw/ccc90625606ba1d83941e4ce5c6be385 to your computer and use it in GitHub Desktop.
vue3-composition-api-import
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