1.2.4 • Published 2 months ago

vue-lite-youtube-embed v1.2.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

vue-lite-youtube-embed

A private by default, faster and cleaner YouTube embed component for Vue applications.

Vue port of React Lite YouTube Embed. Provide videos with a supercharged focus on visual performance. An "Adaptive Loading" way to handle iframes for YouTube.

Installation

npm install vue-lite-youtube-embed

Usage

<script setup>
import LiteYouTubeEmbed from 'vue-lite-youtube-embed'
import 'vue-lite-youtube-embed/style.css'
</script>

<template>
  <LiteYouTubeEmbed
    id="dQw4w9WgXcQ"
    title="Rick Astley - Never Gonna Give You Up (Official Music Video)"
  />
</template>
npm install vue-lite-youtube-embed vue-frag
// src/main.ts
import Vue from 'vue'
import { Fragment } from 'vue-frag'
import App from './App.vue'

Vue.component('Fragment', Fragment)

new Vue({
  render: h => h(App),
}).$mount('#app')
<script setup>
import LiteYouTubeEmbed from 'vue-lite-youtube-embed'
import 'vue-lite-youtube-embed/style.css'
</script>

<template>
  <LiteYouTubeEmbed
    id="dQw4w9WgXcQ"
    title="Rick Astley - Never Gonna Give You Up (Official Music Video)"
  />
</template>

Props

Only two props are required to work: id from the YouTube you want to render and title

PropTypeDescription
idstringId of the video or playlist
titlestringVideo title. Always provide a title for iFrames: https://dequeuniversity.com/tips/provide-iframe-titles Help the web be accessible ;) #a11y
announcestringDefault: Watch. This will be passed to the button in order to be announced to the final user as in Clickable Watch, ${title}, button , customize to match your own language #a11y #i18n
aspectHeightnumberDefault: 9. Use this optional prop if you want a custom aspect-ratio. Please be aware of aspect height and width relation and also any custom CSS you are using.
aspectWidthnumberDefault: 16. Use this optional prop if you want a custom aspect-ratio. Please be aware of aspect height and width relation and also any custom CSS you are using.
activeClassstringPass the string class for the active state
adNetworkbooleanDefault: false To preconnect or not to doubleclick addresses called by YouTube iframe (the adnetwork from Google)
cookiebooleanDefault: false Connect to YouTube via the Privacy-Enhanced Mode using https://www.youtube-nocookie.com You should opt-in to allow cookies
iframeClassstringPass the string class for the own iFrame
mutedbooleanIf the video has sound or not. Required autoplay true to work
paramsstringany params you want to pass to the URL in the iFrame. Two important things to notice: You can assume you just need to add the params, we already setup for you, so you should write start=1150 and not ?start=1150 or &start=1150. You can place more params but it will need to fully form: start=1150&other=value&another=value. First, when you share a YouTube url the param of time is just t, but the embed needs start.
playerClassstringPass the string class for the player, once you can customize it
playlistbooleanUse true when your id be from a playlist
playlistCoverIdstringThe ids for playlists did not bring the cover in a pattern to render so you'll need pick up a video from the playlist (or in fact, whatever id) and use to render the cover. There's a programmatic way to get the cover from YouTube API v3 but the aim of this component is do not make any another call and reduce requests and bandwidth usage as much as possibe
posterstring. One of default mqdefault hqdefault sddefault maxresdefaultDefines the image size to call on first render as poster image. See: https://stackoverflow.com/questions/2068344/how-do-i-get-a-youtube-video-thumbnail-from-the-youtube-api
relstringDefault preload. allows for prefetch or preload of the link url
thumbnailstringPass an optional image url to override the default poster and set a custom poster image
webpbooleanDefault false. When set, uses the WebP format for poster images
wrapperClassstringPass the string class that wraps the iFrame

Events

  • iframeAdded - Fired when iframe is added.

Methods

<script setup>
import { ref } from 'vue'
import LiteYouTubeEmbed from 'vue-lite-youtube-embed'
import 'vue-lite-youtube-embed/style.css'

const iframe = ref(null)

iframe.value?.stopVideo()
iframe.value?.pauseVideo()
iframe.value?.playVideo()
</script>

<template>
  <LiteYouTubeEmbed
    id="dQw4w9WgXcQ"
    ref="iframe"
    title="Rick Astley - Never Gonna Give You Up (Official Music Video)"
  />
</template>

Credits

License

MIT

1.2.4

2 months ago

1.2.3

2 months ago

1.2.1

7 months ago

1.2.0

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.1.2

1 year ago

1.0.4

2 years ago

1.0.2

2 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago