VueYoutube
Intro
A simple component for a powerful API. vue-youtube provides a simple layer for you to use your imagination while over the YouTube IFrame Player API.
Installation
npm install vue-youtube
yarn add vue-youtube
Usage
Bundler (Webpack, Rollup)
import Vue from 'vue'
import VueYoutube from 'vue-youtube'
Vue.use(VueYoutube)
Browser
<script src="vue-youtube/dist/vue-youtube.js"></script>
Example
<youtube :video-id="videoId" ref="youtube" @playing="playing"></youtube>
<button @click="playVideo">play</button>
export default {
data() {
return {
videoId: 'lG0Ys-2d4MA'
}
},
methods: {
playVideo() {
this.player.playVideo()
},
playing() {
console.log('\o/ we are watching!!!')
}
},
computed: {
player () {
return this.$refs.youtube.player
}
}
}
or
<youtube :video-id="videoId" :player-vars="playerVars" @playing="playing"></youtube>
export default {
data() {
return {
videoId: 'lG0Ys-2d4MA',
playerVars: {
autoplay: 1
}
}
},
methods: {
playing() {
console.log('\o/ we are watching!!!')
}
}
}
Events
The component triggers events to notify the parent component of changes in the player. For more information, see YouTube IFrame Player API.
- ready
- ended
- playing
- paused
- buffering
- qued
- error
Player
You have access to all api methods through component referencing.
Example:
<youtube video-id="lG0Ys-2d4MA" ref="youtube"></youtube>
export default {
methods: {
playVideo() {
this.$refs.youtube.player.playVideo()
}
}
}
License
MIT