Skip to content

Instantly share code, notes, and snippets.

@camwhite
Created November 24, 2020 23:39
Show Gist options
  • Save camwhite/c57f56b47c5fdd0baf28cdf7d6025f66 to your computer and use it in GitHub Desktop.
Save camwhite/c57f56b47c5fdd0baf28cdf7d6025f66 to your computer and use it in GitHub Desktop.
<script setup>
import { ref, onMounted } from 'vue'
export const player = ref(null)
const createPlayer = () => {
player.value = new YT.Player('player', {
width: '560',
height: '349',
videoId: 'ScMzIvxBSi4'
})
}
onMounted(() => {
if (!window.YT) {
const tag = document.createElement('script')
tag.src = 'https://www.youtube.com/player_api'
document.body.appendChild(tag)
window.onYouTubeIframeAPIReady = function() {
createPlayer()
}
} else {
createPlayer()
}
})
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment