vue-youtube-embed icon indicating copy to clipboard operation
vue-youtube-embed copied to clipboard

Using vue-youtube-embed in Nuxt.js

Open milospantelinac opened this issue 6 years ago • 11 comments

I have got problem with vue-youtube-embed. I don't know to implement in Nuxt.js project. I had install vue-youtube-embed across npm. Do anybody can to write the implementation process? PLS

milospantelinac avatar Jun 08 '18 16:06 milospantelinac

I solve the problem using nuxt's plugins

  1. add file in plugins folder name youtube.js(or what you want)
  2. edit youtube.js write

import Vue from 'vue'

import VueYouTubeEmbed from 'vue-youtube-embed'

Vue.use(VueYouTubeEmbed)

Vue.use(VueYouTubeEmbed, { global: true })
  1. edit nuxt.config.js write
plugins: [
    '@/plugins/vuetify',
    '@/plugins/youtube'
  ]
  1. restart npm run dev and use no-ssr way to use <youtube> component like this
<no-ssr  placeholder="Loading...">
             <youtube  @ready="ready" :player-vars="{ autoplay: 1 }" :player-width="100" :player-height="100" :video-id="play" />
       </no-ssr>

this is my Solution if have better solution plz tell me.

dandanXO avatar Jun 20 '18 22:06 dandanXO

I've had to import the plugin this way to work properly in nuxt instead.

plugins: [ { src: '@/plugins/youtube.js', ssr: false } ]

Also, i didn't need the <no-ssr /> tag.

leofachini avatar Mar 18 '19 00:03 leofachini

another thing I had to change from the provided example code to make this work, was to turn

data: {
    videoId: 'videoId',
},

into:

data() {
    return {
        videoId: 'videoId'
    }
},

phivk avatar Mar 20 '19 15:03 phivk

Anyone knows how to get access to these methods in nuxt.js?

  • getIdFromURL
  • getTimeFromURL

catman85 avatar May 17 '19 15:05 catman85

You may want to add the plugin to the transpile build option as such:

build: { transpile : ['vue-youtube-embed'] }

That should do it.

lystun avatar Oct 13 '20 10:10 lystun

@lystun That was the missing piece of the puzzle for me. Thanks!

cam424 avatar Oct 28 '20 23:10 cam424

this.videoId = this.$youtube.getIdFromURL(this.link) @catman85

engrmafzaalch avatar Jan 15 '21 12:01 engrmafzaalch

Hey... for anyone still stuck here... I got it working this way:

First create a js file in the plugins directory with the following code. Mine is called vue-youtube-player.js

import VueYouTubeEmbed, {YouTubePlayer} from "vue-youtube-embed";
import Vue from "vue";

Vue.use(VueYouTubeEmbed, {global: true});

Vue.component('vue-youtube-player', YouTubePlayer)

As far as I understand why, it's because VueYouTubeEmbed is a plugin, not a component. So this way we tell Vue to use the plugin but also register the component.

Add this file to nuxt.config.js in your plugins:

  ...
  plugins: [
    '~/plugins/vue-youtube-player.js',
  ],
  ...

Then in the component or page you want to use the player:

    ...
     <client-only>
         <vue-youtube-player :video-id="videoID"></vue-youtube-player>
    </client-only>
    ...   
    
 <script>
    export default {
      data() {
          return {
              videoID: "VL_r7jtt7PA"
          }
       }
     }
</script>

Hope this helps :)

SameeranB avatar May 05 '21 19:05 SameeranB

how do i hide the logo and reference video in nuxt.js?

ihsanfy avatar Jun 02 '21 05:06 ihsanfy

I followed the steps but I'm getting this error!

An error occurred. Please try again later. (Playback ID: 0jp1TNFmXFgYNYmf)

Please help!

yiyasha15 avatar Jun 13 '21 16:06 yiyasha15

you are trying to bind video-id so it gives error because there is no value for that.

 <youtube :video-id="ogfYd705cRs"></youtube> this example in your case must be <youtube video-id="ogfYd705cRs"></youtube>

I hope this helps if I am right to understand your problem.

I followed the steps but I'm getting this error!

An error occurred. Please try again later. (Playback ID: 0jp1TNFmXFgYNYmf)

Please help!

Dan88Hus avatar Jul 29 '21 08:07 Dan88Hus