Skip to content

Instantly share code, notes, and snippets.

@hang15
Last active February 10, 2021 14:53
Show Gist options
  • Save hang15/87107dbe30a5a179234fef7726ac0ea3 to your computer and use it in GitHub Desktop.
Save hang15/87107dbe30a5a179234fef7726ac0ea3 to your computer and use it in GitHub Desktop.
<template>
<div>
<label>User Query:</label>
<input v-model="query" :disabled="loading" ></input>
<button @click="getData({ query })" :busy="loading" />
<User v-if="data != null || error != null" :data="data" :error="error" />
</div>
</template>
<script>
import axios from "axios";
import User from "../components/User.vue";
import useFetcher from "../composables/useFetcher";
async function userFetcher(params) {
const data = await axios.get("/api/user", { params });
return data;
}
export default {
components: {
User,
},
data() {
return {
query: "",
},
},
setup() {
const { data, loading, error, getData } = useFetcher(userFetcher);
return { data, loading, error, getData };
},
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment