-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.vue
59 lines (47 loc) · 1.42 KB
/
App.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<template>
<div class="container">
<SearchBar v-on:termChange="onTermChange"></SearchBar>
<div class="row">
<VideoDetail v-bind:video="selectedVideo"/>
<VideoList @videoSelect="onVideoSelect" v-bind:videos="videos"></VideoList>
</div>
</div>
</template>
<script>
import axios from 'axios';
import SearchBar from './components/SearchBar';
import VideoList from './components/VideoList';
import VideoDetail from './components/VideoDetail';
const API_KEY = 'AIzaSyCCiM9V1KH6WdAhyGWZEMUXOPxlJf7ocsY'
export default {
name: 'App', //define properties within default
components: {
SearchBar: SearchBar,
VideoList: VideoList,
VideoDetail
},
data(){
return { videos: [], selectedVideo: null }; //initializes data, array of objects
},
methods: {
onTermChange(searchTerm){
//executes youtube query w/ promise
axios.get('https://www.googleapis.com/youtube/v3/search', {
params: {
key: API_KEY,
type: 'video',
part: 'snippet',
q: searchTerm
}
}).then(response => {
this.videos = response.data.items //response from youtube api
});
},
onVideoSelect(video) {
this.selectedVideo = video;
}
}
}
</script>
<style>
</style>