网页移动端 vue-video-player 视频播放器使用记录
完整的代码, 可以复制引用
引入视频播放器插件
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>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2020-03-03 flutter-mac配置电脑环境