How to Create an Interactive YouTube Video Selection in Vue.js

How to Create an Interactive YouTube Video Selection in Vue.js

In this post I want to share my observations during my implementation of an **interactive** YouTube Video selection in Vue. Maybe this can save you some time, if you plan to do the same.

Let’s start with my motivation. It came from the improvements of the #BlueCloudMirror game UI. We decided to provide the #BlueCloudMirror users a recorded YouTube LiveStream of us. This video provides an awesome overview of our major technologies.

The video takes approximately 50 minutes. This is a long time to watch, so we want to provide the user a new interactive architecture page, as you can see below. A user should have the ability to select the topic they is interested in. To do this, we needed the position selection for the YouTube video. In the gif you can see the result.


Topics of this blog post:

  • How to define dynamic values in a Vue template.
  • How to configure autostart for YouTube videos.
  • How to avoid SAMEORI problem with the YouTube video.

How to Define Dynamic Values in a Vue Template

You can find the code of the Architecture.vue file on GitHub.

For the UI, I used the option template, and for the event handling the options methods and data.

To show you a high level view of how the code works, I made a very simplified sequence diagram.


Details of the Sequence Diagram

1. V-BIND onClick Event

The following code shows that the Vue template contains the button. This button will trigger an event. The definition for this event is defined using v-on together with the related method onYouTubeDemo.

         background-color: #FFFFFF;
 ><fontcolor="black">Game demo [5:03 mins]</font>

2. Set the Right Value for 'Game Demo'

The method  onYouTubeDemo is called by clicking the button we defined before. Inside this method, the internal JSON array variable sets the right YouTube video URL, for using in the templatefor the UI later.

In the following code, you can see the internal JSON array variable definition of youtubedata.The JSON array reflects the properties to display the video in an iFrame later.

var youtubedata = {     
  "0":{ width:"853",       
        src:";amp;amp;start=303",                        frameborder:"0",       allow:"accelerometer; autoplay; encrypted-media; gyroscope;  picture-in-picture", 
        allowfullscreen:"" }};

Inside the code below, in  methods, the event method  onYouTubeDemo is responsible for setting the right video URL for the previouly defined JSON array variable youtubedata.The variable is used in the data option later.

methods: {   
  onYouTubeDemo() {   

Data organizes the data exchange for the web front-end with these variables youtubeJSON:youtubedata. You can find more details in the Vue best practices docs.

data: function () {   
    return {youtubeJSON:youtubedata}},

3. Show the Video in an iFrame

With the v-bind, key and v-for we are setting the right data values for the YouTube video to display inside an iFrame. Here you can find the variable youtubeJSON. The blog post Use JSON to dynamically build web pages with Vue.js is awesome help for more details.

   v-for="data in youtubeJSON"


I discovered on the internet: you have to ensure that the youtube url contains the parameter autoplay and the value is set to 1.


How to Avoid the SAMEORI Problem

The SAMEORI problem, in our case, is when you cannot display the video in a iFrame. To avoid the SAMEORI problem, simply ensure you use embed in your YouTube URL in the source code. A very useful note is on Stack Overflow related to the “sameori” error


This was all about my observations during my implementation of an interactive YouTube Video selection in Vue.

Thanks For Visiting, Keep Visiting

If you liked this post, share it with all of your programming buddies!

This post was originally published here

vue-js web-development

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Hire Web Developer

Looking for an attractive & user-friendly web developer?, a leading web, and mobile app development company, offers web developers for hire through flexible engagement models. You can **[Hire Web...

Top Vue.js Developers in USA

Vue.js is an extensively popular JavaScript framework with which you can create powerful as well as interactive interfaces. Vue.js is the best framework when it comes to building a single web and mobile apps.

Hire Node.JS Developers | Skenix Infotech

We are providing robust Node.JS Development Services with expert Node.js Developers. Get affordable Node.JS Web Development services from Skenix Infotech.

Why Web Development is Important for your Business

With the rapid development in technology, the old ways to do business have changed completely. A lot more advanced and developed ways are ...

8 Popular Websites That Use The Vue.JS Framework

In this article, we are going to list out the most popular websites using Vue JS as their frontend framework. Vue JS is one of those elite progressive JavaScript frameworks that has huge demand in the web development industry. Many popular websites are developed using Vue in their frontend development because of its imperative features.