This plugin is deprecated. Please use the new and improved @vue-youtube/core plugin.
This plugin makes it easy to integrate the YouTube Iframe API into your Vue app. This plugin is Vue V3 compatible.
npm install @techassi/vue-youtube-iframe --saveor
yarn add @techassi/vue-youtube-iframemain.js / main.ts
import { createApp } from 'vue';
import App from './App.vue';
import YoutubeIframe from '@techassi/vue-youtube-iframe';
createApp(App).use(YoutubeIframe).mount('#app');YourComponent.vue
<template>
<youtube-iframe :video-id="YT_VIDEO_ID"></youtube-iframe>
</template>YourComponent.vue
<template>
<youtube-iframe
:video-id="YT_VIDEO_ID"
:player-width="WIDTH"
:player-height="HEIGHT"
:no-cookie="TRUE / FALSE"
:player-parameters="YT_PLAYER_PARAMS"
@EVENT="CALLBACK"
></youtube-iframe>
</template>Vue currently doesn't support typings when using a component in a SFC and accessing it via ref / this.$refs. There
is a way to bring in typings when using ref. Please note: This isn't the most elegant solution.
<template>
<youtube-iframe :video-id="YT_VIDEO_ID" ref="yt"></youtube-iframe>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { Player } from '@techassi/vue-youtube-iframe';
export default defineComponent({
name: 'App',
mounted() {
const player = this.$refs.yt as typeof Player;
// Variable player now has typings
},
});
</script>:videoId / :video-id: Specify the YT video id (e.g.dQw4w9WgXcQ):playerWidth / :player-width: Specify the player's width in pixels:playerHeight / :player-height: Specify the player's height in pixels:noCookie / :no-cookie: If set totruethe host will be set tohttps://www.youtube-nocookie.com:playerParameters / :player-parameters: Set player parameters, see here
For the available player parameters see here
@ready, @error, @state-change
For detailed event information check here