Last active
July 5, 2020 17:10
-
-
Save MartinMalinda/91dc7cd15e130945e6151e6b78a4e7be 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
export default defineComponent({ | |
setup() { | |
const data = ref(null); | |
const error = ref(null); | |
const isLoading = ref(false); | |
const fetchUsers = async () => { | |
try { | |
isLoading.value = true; | |
const response = await axios('/api/users'); | |
data.value = response.data.data.map(user => ({ | |
...user, | |
createdAt: new Date(user.createdAt) | |
})); | |
} catch (e) { | |
error.value = e; | |
} finally { | |
isLoading.value = false; | |
} | |
}; | |
fetchUsers(); | |
return { data, error, isLoading, fetchUsers }; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment