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> </button>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<youtube-player :url="video" :allowfullscreen="'false'"/> <youtube-player :url="video"/>
</div> </div>
</div> </div>
</div> </div>

View File

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