Last active
February 10, 2021 14:53
-
-
Save hang15/87107dbe30a5a179234fef7726ac0ea3 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
<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