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/6399e1893a88957b9ace9422d9c0397e to your computer and use it in GitHub Desktop.
Save letswritetw/6399e1893a88957b9ace9422d9c0397e to your computer and use it in GitHub Desktop.
vue3-composition-api-import
import { ref } from 'vue'
export default function() {
const users = ref(null);
const getData = async () => {
try {
const data = await fetch('https://jsonplaceholder.typicode.com/users');
if(!data.ok) {
throw Error('fetch data 失敗');
}
users.value = await data.json();
} catch(error) {
throw Error(error)
}
}
return { users, getData }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment