Created
December 17, 2017 13:20
-
-
Save manegame/fe2205c356a1d5f618e5eda76d49d01e to your computer and use it in GitHub Desktop.
Vue Youtube embed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div class="youtube" :class="{'youtube--show': noframed}"> | |
<youtube :video-id='id' @ready="ready"></youtube> | |
</div> | |
</template> | |
<script> | |
import { getIdFromURL } from 'vue-youtube-embed' | |
import noframe from 'reframe.js' | |
export default { | |
name: 'bac-youtube-embed', | |
props: { | |
url: { | |
type: String, | |
required: true | |
} | |
}, | |
data() { | |
return { | |
noframed: false, | |
iframe: '' | |
} | |
}, | |
computed: { | |
id() { | |
return getIdFromURL(this.url) | |
} | |
}, | |
methods: { | |
ready (player) { | |
this.iframe = player.getIframe() | |
if (!this.noframed) { | |
noframe(this.iframe) | |
this.noframed = true | |
} | |
} | |
} | |
} | |
</script> | |
<style scoped lang='scss'> | |
.youtube { | |
width: 100%; | |
opacity: 0; | |
text-align: center; | |
&::after { | |
content: 'retrieving video'; | |
} | |
&--show { | |
opacity: 1; | |
&::after { | |
content: ''; | |
} | |
} | |
} | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment