feat: Added youtube video component

This commit is contained in:
scmmishra
2019-03-28 13:44:25 +05:30
parent 92e311d9d7
commit 29aaee1488

View File

@@ -2,9 +2,7 @@
<div> <div>
<section class='video-top-section video-section-bg'> <section class='video-top-section video-section-bg'>
<div> <div>
<div class="embed-responsive embed-responsive-16by9"> <youtube-player :url="contentData.url"/>
<iframe class="embed-responsive-item" :src="'https://www.youtube.com/embed/' + videoID" allowfullscreen></iframe>
</div>
<div class="mt-3 row"> <div class="mt-3 row">
<div class="col-md-8"> <div class="col-md-8">
<h2>{{ contentData.name }}</h2> <h2>{{ contentData.name }}</h2>
@@ -37,19 +35,22 @@
</div> </div>
</template> </template>
<script> <script>
import YoutubePlayer from './YoutubePlayer.vue'
export default { export default {
props: ['content', 'type'], props: ['content', 'type'],
name: 'Video', name: 'Video',
data() { data() {
return { return {
contentData: '', contentData: '',
videoID: '',
} }
}, },
components: {
YoutubePlayer
},
mounted() { mounted() {
this.getContent() this.getContent()
.then(data => this.contentData = data) .then(data => this.contentData = data)
.then((contentData) => this.videoID = this.getVideoID(this.contentData.url))
}, },
methods: { methods: {
getContent() { getContent() {
@@ -57,19 +58,6 @@ export default {
type: this.type, type: this.type,
content: this.content content: this.content
}) })
},
getVideoID(link) {
if (!Array.prototype.last){
Array.prototype.last = function(){
return this[this.length - 1];
};
};
if (link.includes('v=')){
return link.split('v=')[1].split('&')[0]
}
else if (link.includes('youtu.be')) {
return link.split('/').last().split('?')[0]
}
} }
} }
}; };