feat: refactored YoutubePlayer component

This commit is contained in:
scmmishra 2019-03-28 13:44:05 +05:30
parent 15f6faad9b
commit 92e311d9d7
2 changed files with 18 additions and 8 deletions

View File

@ -9,7 +9,7 @@
</button>
</div>
<div class="modal-body">
<youtube-player :url="video" :allowfullscreen="'false'"/>
<youtube-player :url="video"/>
</div>
</div>
</div>

View File

@ -6,19 +6,29 @@
<script type="text/javascript">
export default {
name: 'YoutubePlayer',
props: ['url', 'allowfullscreen'],
computed: {
videoID() {
props: ['url'],
data() {
return {
videoID: ''
}
},
watch: {
url() {
this.videoID = this.getVideoID(this.url)
}
},
methods: {
getVideoID(link) {
if (!Array.prototype.last){
Array.prototype.last = function(){
return this[this.length - 1];
};
};
if (this.url.includes('v=')){
return this.url.split('v=')[1].split('&')[0]
if (link.includes('v=')){
return link.split('v=')[1].split('&')[0]
}
else if (this.url.includes('youtu.be')) {
return this.url.split('/').last().split('?')[0]
else if (link.includes('youtu.be')) {
return link.split('/').last().split('?')[0]
}
}
}