VueTube/NUXT/pages/search.vue

73 lines
1.7 KiB
Vue
Raw Normal View History

2022-03-03 18:05:50 +00:00
<template>
2022-03-22 01:13:48 +00:00
<div class="accent">
<center v-if="videos.length == -1">
2022-03-17 21:54:06 +00:00
<v-skeleton-loader type="card-avatar, article, actions" />
<v-skeleton-loader type="card-avatar, article, actions" />
2022-03-04 14:32:09 +00:00
</center>
2022-03-22 01:13:48 +00:00
<v-list-item v-for="(video, index) in videos" :key="index" class="pa-0">
<v-card class="entry background" :to="`/watch?v=${video.id}`" flat>
<div style="position: relative">
<v-img :src="video.thumbnails[video.thumbnails.length - 1].url" />
<div
class="videoRuntimeFloat"
style="color: #fff"
v-text="video.runtime"
/>
</div>
<div class="px-4 pt-4" v-text="video.title" />
<v-card-text class="pt-0">
2022-03-13 20:59:01 +00:00
<div v-text="`${video.views} ${video.uploaded}`" />
2022-03-03 23:13:14 +00:00
</v-card-text>
</v-card>
</v-list-item>
2022-03-03 18:05:50 +00:00
</div>
</template>
2022-03-04 02:25:30 +00:00
<style scoped>
.entry {
width: 100%; /* Prevent Loading Weirdness */
2022-03-04 02:25:30 +00:00
}
.videoRuntimeFloat {
position: absolute;
bottom: 10px;
right: 10px;
background: rgba(0, 0, 0, 0.5);
border-radius: 5px;
2022-03-22 01:13:48 +00:00
padding: 0px 4px 0px 4px;
}
2022-03-04 02:25:30 +00:00
</style>
2022-03-03 18:05:50 +00:00
<script>
export default {
data() {
return {
2022-03-21 05:13:21 +00:00
videos: [],
};
2022-03-03 18:05:50 +00:00
},
mounted() {
2022-03-22 08:23:23 +00:00
getSearch();
},
methods: {
getSearch() {
const searchQuestion = this.$route.query.q;
const vm = this;
this.$youtube.search(searchQuestion, (data) => {
vm.videos = data;
});
},
},
watch: {
// Watches for new searches while the current search page is active.
$route: {
deep: true,
handler(newSearch, oldSearch) {
if (newSearch.query.q != oldSearch.query.q) {
this.getSearch();
}
},
},
2022-03-21 05:13:21 +00:00
},
};
2022-03-03 18:05:50 +00:00
</script>