1. 程式人生 > 其它 >VUE使用video.js

VUE使用video.js

一、下載video.js

npm install --save-dev video.js

二、在vue腳手架中引入video.js(main.js引入)

import Video from 'video.js'
import 'video.js/dist/video-js.css'
Vue.prototype.$video = Video //引入Video播放器

三、例項化了視訊.js播放器,並在 上銷燬了它

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

<script>
import videojs 
from 'video.js';
//不要忘記包括視訊.js CSS,位於 .video.js/dist/video-js.css 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>

三、元件使用video.js

<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" } ] } }; } };