Skip to content

Instantly share code, notes, and snippets.

@hang15
Last active February 10, 2021 14:54
Show Gist options
  • Save hang15/71af3f0482a681875f8b7f24537ee1c6 to your computer and use it in GitHub Desktop.
Save hang15/71af3f0482a681875f8b7f24537ee1c6 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" :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