VueYoutube
A Vue.js Plugin
Installation
npm install --save 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>
<script src="https://unpkg.com/vue-youtube"></script>
Example
<youtube :video-id="videoId" ref="youtube" @playing="playing"></youtube>
export default {
data() {
return {
videoId: 'lG0Ys-2d4MA'
}
},
methods: {
playing() {
console.log('\o/ we are watching!!!')
}
},
computed: {
player () => this.$refs.youtube.player
},
mounted() {
this.player.playVideo()
}
}
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()
}
}
}
Development
Launch visual tests
npm run dev
Launch Karma with coverage
npm run dev:coverage
Build
Bundle the js and css of to the dist
folder:
npm run build
Publishing
The prepublish
hook will ensure dist files are created before publishing. This
way you don't need to commit them in your repository.
npm version
git push --follow-tags
npm publish
TODO
License
MIT