---------------------引入VIDEO依赖--------------------------------------
npm install video.js
---------------------外部VUE引入VIDEO组件---------------------------
<videoPlayer
v-if="visible"
:options="playerOptions"
/>
<script>
import videoPlayer from '@/components/videoPlayer'
export default {
name: 'view',
data () {
return {
playerOptions: {
muted: false,
language: 'zh-CN',
playbackRates: [0.5, 1.0, 1.5, 2.0],
autoplay: false,
sources: [
{
type: 'video/mp4',
src: ''
}
]
}
}
},
components: { videoPlayer }
}
</script>
---------------------VIDEO组件---------------------------------
<template>
<div class="video-js-comp">
<video
ref="videoPlayer"
class="video-js"
controls
/>
</div>
</template>
<script>
import videojs from 'video.js'
import 'videojs-flash'
import 'video.js/dist/video-js.css'
import CN from 'video.js/dist/lang/zh-CN.json'
videojs.addLanguage('zh-CN', CN)
export default {
name: 'VideoPlayer',
props: {
options: {
type: Object,
default () {
return {}
}
},
dispose: {
type: Boolean,
required: true
}
},
data () {
return {
player: null
}
},
watch: {
dispose (newVal) {
if (!newVal && this.player) {
this.player.dispose()
}
}
},
mounted () {
this.player = videojs(this.$refs.videoPlayer, this.options)
}
}
</script>
<style lang="scss" scoped>
.video-js-comp,
.video-js {
width: 100%;
height: 100%;
}
</style>
1613

被折叠的 条评论
为什么被折叠?



