feat: refactored YoutubePlayer component
This commit is contained in:
parent
15f6faad9b
commit
92e311d9d7
@ -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>
|
||||||
|
|||||||
@ -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]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user