1
0
mirror of https://github.com/videojs/video.js.git synced 2024-12-14 11:23:30 +02:00
video.js/docs/guides/vue.md
Otis Wright 4c277fd0f6 docs: add an example Vue integration.md (#5899)
* Create vue.md

Instructions for Vue integration (based on React example).

* Add link to Vue guide
2019-03-28 19:56:29 -04:00

1.5 KiB

Video.js and Vue integration

Here's a basic Vue player implementation.

It just instantiates the Video.js player on mounted and destroys it on beforeDestroy.

<template>
    <div>
        <video ref="videoPlayer" class="video-js"></video>
    </div>
</template>

<script>
import videojs from 'video.js';

export default {
    name: "VideoPlayer",
    props: {
        options: {
            type: Object,
            default() {
                return {};
            }
        }
    },
    data() {
        return {
            player: null
        }
    },
    mounted() {
        this.player = videojs(this.$refs.videoPlayer, this.options, function onPlayerReady() {
            console.log('onPlayerReady', this);
        })
    },
    beforeDestroy() {
        if (this.player) {
            this.player.dispose()
        }
    }
}
</script>

You can then use it like this: (see options guide for option information)

<template>
  <div>
		<video-player :options="videoOptions"/>
	</div>
</template>

<script>
import VideoPlayer from "@/components/VideoPlayer.vue";

export default {
	name: "VideoExample",
	components: {
		VideoPlayer
	},
	data() {
		return {
			videoOptions: {
				autoplay: true,
				controls: true,
				sources: [
					{
						src:
							"/path/to/video.mp4",
						  type: "video/mp4"
					}
				]
			}
		};
	}
};

Don't forget to include the Video.js CSS, located at video.js/dist/video-js.css.