Skip to content

Instantly share code, notes, and snippets.

@MartinMalinda
Created July 6, 2020 14:42
Show Gist options
  • Save MartinMalinda/c5507cdb43c24c82c857e8fc208d6ad3 to your computer and use it in GitHub Desktop.
Save MartinMalinda/c5507cdb43c24c82c857e8fc208d6ad3 to your computer and use it in GitHub Desktop.
export default defineComponent({
setup() {
const store = useStore();
const { data, error, isLoading, run: fetchUsers } = useAsync(async () => {
if (store.getters.hasUsers) {
return store.getters.users;
}
const response = await axios('/api/users');
const users = normalizeFindUsersResponse(response);
store.commit('setUsers', users);
return users;
});
return { data, error, isLoading, fetchUsers };
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment