Last active
February 10, 2021 14:54
-
-
Save hang15/71af3f0482a681875f8b7f24537ee1c6 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" :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"; | |
export default { | |
components: { | |
User | |
}, | |
data () { | |
return { | |
query: "", | |
loading: false, | |
data: null, | |
error: null | |
} | |
}, | |
methods: { | |
async getData() { | |
this.loading = true; | |
this.data = null; | |
this.error = null; | |
try { | |
const data = await axios.get("/api/user", { | |
params: { query: this.query } | |
}); | |
this.data = data; | |
} catch (error) { | |
this.error = error; | |
} finally { | |
this.loading = false; | |
} | |
}, | |
}, | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment