完整的代码, 可以复制引用
引入视频播放器插件
npm i vue-video-player -D
import VideoPlayer from 'vue-video-player'
require('video.js/dist/video-js.css')
require('vue-video-player/src/custom-theme.css')
Vue.use(VideoPlayer)
组件模板
<template>
<section class="my-video">
<TopBar title="video" />
<section ref="goods_swipe" class="goods-swipe" v-for="(item,index) in videoList" :key="index">
<section class="video-title">
怎么赚钱
</section>
<video-player class="goods-video" ref="videoPlayer" :options="videoList[index]"></video-player>
</section>
</section>
</template>
<script>
import TopBar from '@/components/TopBar';
export default {
name: "video",
components: {
TopBar
},
data() {
return {
current: 0, // 当前是视频还是图片,0代表视频
videoList: [ // 视频列表
{
fluid: true,
aspectRatio: '16:9',
poster: '',
sources: [{
type: "video/mp4",
src: 'http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4'
}]
},
{
fluid: true,
aspectRatio: '16:9',
poster: '',
sources: [{
type: "video/mp4",
src: 'http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4'
}]
},
]
}
},
computed: {
player() {
return this.$refs.videoPlayer.player; // 获取视频播放器对象
},
},
mounted() {
},
methods: {
onChange(index) {
this.current = index; // 修改当前类型
this.player.pause(); // 暂停播放
},
},
}
</script>
<style scoped lang="less">
.my-video {
.video-title{
text-align: center;
padding:10px 0 8px;
font-family: Alhyznht;
color: #ccc;
}
.goods-swipe {
position: relative;
width: 100%;
background: #000;
margin-top: 15px;
.van-swipe{
overflow: auto;
}
.goods-video {
height: 100%;
.video-js {
width: 100%;
height: 100%;
}
.vjs-tech{
height: auto;
}
.vjs-control-bar {
bottom: 40px;
}
/deep/ .vjs-big-play-button {
border-radius: 50%;
width: 40px;
height: 40px;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
margin: 0;
line-height: normal;
.vjs-icon-placeholder {
&:before {
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: auto;
height: auto;
}
}
}
.vjs-control-bar {
.vjs-play-control,
.vjs-fullscreen-control {
.vjs-icon-placeholder {
&:before {
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: auto;
height: auto;
font-size: 25px;
}
}
}
.vjs-volume-panel,
.vjs-picture-in-picture-control {
display: none;
}
}
}
}
}
</style>