How to Setup VideoJS with VueJS?
Last Updated :
17 May, 2024
Video.js is a popular javascript library that allows support for various video playback formats on the web. With it, we can embed and customize our video components in our web pages that are made in various frontend frameworks like, Vue.js, React, Angular, etc. In this article, we will learn how to setup video.js with Vue.js frontend framework.
Steps to Setup Video.js with VueJS
Step 1: In this step, we will create a vue app with the below commands. We will then use this app to use video.js library.
vue create video-js
Step 2: Now, install the video.js library as well with the below command:
pnpm install video.js
This will create a sample Vue application with the below project structure.
Project structure:

Step 3: Creating a Video.vue component.
In this step, we will create a Video.vue component file inside the "src" directory, and use the video.js library to setup a customizable video playback in our component. We will create a videoOptions data variable that holds all the config that is required by the video-js library to play the video. And when the component gets mounted, we will initialize the player with the config and the source. and we will use the Video.vue component in our App.vue file, so it is visible in our web page when we run the server. We will import the Video component that we created above, and use that inside the template.
Example: This example shows the use of video.js
JavaScript
<template>
<div>
<video ref="videoJsPlayer"
class="video-js vjs-defaultskin"></video>
</div>
</template>
<script>
import videojs from "video.js";
export default {
name: "VideoJsPlayer",
data() {
return {
player: null,
videoOptions: {
autoplay: true,
controls: true,
preload: true,
fluid: true,
sources: [
{
src:
"https://media.geeksforgeeks.org/wp-content/uploads/20240514215354/Untitled-design-(8).mp4",
type: "video/mp4",
},
],
},
};
},
mounted() {
this.player = videojs(
this.$refs.videoJsPlayer,
{
...this.videoOptions,
innerHeight: 360,
innerWidth: 640,
},
() => {
this.player.log("video player ready", this);
}
);
},
beforeUnmount() {
if (this.player) {
this.player.dispose();
}
},
};
</script>
<style scoped>
video {
width: 400px;
}
</style>
JavaScript
<-- Ap.vue-->
<template>
<Video />
</template>
<script>
import Video from './Video.vue'
export default {
name: 'App',
components: {
Video
}
}
</script>
Step 4: Run the server
Now, we will run our web application by running the below command:
pnpm serve
Output:
Similar Reads
How to Use Moment.js with Vuejs? The Moment.js library can be integrated with Vue.js to simplify date and time manipulation within your Vue components. By importing Moment.js and using its formatting functions, you can easily display and format dates in your application. This integration allows you to use Moment.js's powerful featu
2 min read
How to Integrate Vite with Vue.js? Vite provides the flexibility and speed needed for modern web development by offering a fast-build tool and development server. Integrating Vite with Vue.js allows developers to use Viteâs efficient hot module replacement and optimized build processes while working with Vue's reactive framework. Thi
3 min read
Build a Movie App with VueJS We will build a movie application using Vue.js. By the end, you'll have a fully functional movie app that will allow users to search for movies, view their details, and get information such as title, year, rating, and plot. Prerequisites:Vue.jsNode.js and npm are installed on your system.Approach Vu
5 min read
How to add Youtube Videos in Next.js ? In this article, we are going to learn how we can add Youtube Video in NextJs. NextJS is a React-based framework. It has the power to Develop beautiful Web applications for different platforms like Windows, Linux, and mac. The linking of dynamic paths helps in rendering your NextJS components condit
2 min read
How to replace jQuery with Vue.js ? In this article, we will see how to replace jQuery with Vue. jQuery: jQuery is a fast and rich JavaScript library. It is an application programming interface (API), a cross-platform JavaScript library designed to improve web browser features. It makes things easier like works across HTML document tr
6 min read
How to Host WordPress Videos ? Hosting videos on your WordPress site can greatly enhance user engagement and improve your site's SEO. Video is crucial for engagement, with many brands and creators using it to connect with their target audience. If you're using WordPress, you might wonder if it can host videos. While WordPress doe
6 min read