My vue learning curve: I noticed that the input filed sends a call via ajax (axios) to YouTube on every key entered in the input filed. So one letter it already perform the search over in YouTube search APi. I am guessing that for using this method to search over a database by keywords and etc this would have worked perfectly but when using API such as YouTube videos it should work better if it could wait until the user finish up his search query. So my question is there a directive or any other way to force the API call to wait for the user to finish up his search query before it runs the call over in YouTube? BTW I am exceeding my 1,000 limit over YouTube API in like 1 hour while testing.
This is the App.vue
<template>
<SearchBar @emitTermSearch="onTermSearch"></SearchBar>
<VideoList :videos="videos"></VideoList>
</template>
<script>
import axios from "axios";
import SearchBar from "./components/SearchBar";
const API_KEY = "hidden";
export default {
name: "App",
components: {
SearchBar
},
data() {
return {
videos: []
};
},
methods: {
onTermSearch(emitTermSearch) {
axios
.get("https://www.googleapis.com/youtube/v3/search", {
params: {
key: API_KEY,
type: "video",
part: "snippet",
maxResults: 2,
order: "date",
q: emitTermSearch
}
}.then(response => {
this.videos = response.data.items;
}).catch(err => {
console.log(err);
});
}
}
};
</script>
This is the SearcBar.vue
<template>
<h1>Please Search</h1>
<div id="searchbar">
<input @input="onInput" />
</div>
</template>
<script>
export default {
name: "SearchBar",
methods: {
onInput(event) {
this.$emit("emitTermSearch", event.target.value);
}
}
};
</script>