Vue YouTube Embed
This is a component for Vue.js to utilize YouTube iframe API easily. This is based on Angular YouTube Embed
License
MIT License
install
or
// NPMnpm i -S vue-youtube-embed // or with Yarnyarn add vue-youtube-embed
Vue// if you don't want install the component globallyVue// if you want to install the component globally with a different nameVue
Usage
Please pass the ID of the video that you'd like to show.
<!-- or with a custom component identifier -->
Props
These are available props.
player-width
:String
orNumber
, default value is640
player-height
:String
orNumber
, default value is360
player-vars
:Object
, default value is{start: 0, autoplay: 0}
Can also specifyrel
.video-id
:String
,required
mute
:Boolean
default value isfalse
host
:String
default value ishttps://www.youtube.com
. Can be set tohttps://www.youtube-nocookie.com
as well.
Methods
These functions are the same as the original one.
getIdFromURL
getTimeFromURL
let videoId = let startTime =
or
methods: { thisvideoId = this$youtube thisstartTime = this$youtube }
Events
These are the events that will be emitted by the component.
ready
ended
playing
paused
buffering
qued
error
The first argument contains the instance of YT.Player
at the parameter target
.
The way of start playing video automatically
Example on vue-play
// yarn or npmyarn installyarn run play
Example code
listening events add options
'use strict' Vue const app = el: '#app' data: videoId: 'videoId' methods: { thisplayer = eventtarget } { // The player is playing a video. } { // when you change the value, the player will also change. // If you would like to change `playerVars`, please change it before you change `videoId`. // If `playerVars.autoplay` is 1, `loadVideoById` will be called. // If `playerVars.autoplay` is 0, `cueVideoById` will be called. thisvideoId = 'another video id' } { thisplayer } { thisplayer }
Usage with Nuxt SSR
To get this component working with Nuxt, wrap it in Nuxt's no-ssr
component.
Contribution
contribution welcome!