Video 视频
播放视频
基础用法
使用poster
设置封面,使用src
设置视频播放地址
视频尺寸建议使用 max-width 或者 width、height 属性
vue
<template>
<el-flex vertical align="center">
<el-video
style="max-width: 450px"
duration="0:05"
poster="https://realbot-oss.oss-accelerate.aliyuncs.com/scrm/2025/2025-05-21/659fa31d-dc87-4882-8be5-1fba8fb7e6ff/flower.mp4?x-oss-process=video/snapshot,t_1000,f_jpg,m_fast"
src="https://realbot-oss.oss-accelerate.aliyuncs.com/scrm/2025/2025-05-21/659fa31d-dc87-4882-8be5-1fba8fb7e6ff/flower.mp4"
/>
</el-flex>
</template>
隐藏源代码
自定义 UI
使用play-icon
插槽设置播放按钮
也可以使用poster
duration
default
插槽 分别设置 封面
时长
video回退内容
vue
<template>
<el-flex vertical align="center">
<el-video
duration="10:53"
style="max-width: 180px"
poster="https://realbot-oss.oss-accelerate.aliyuncs.com/scrm/2025/2025-22-19/ab77e3d0-8933-4746-94af-bb66f6e58d38/视频.mp4?x-oss-process=video/snapshot,t_1000,f_jpg,m_fast"
src="https://realbot-oss.oss-accelerate.aliyuncs.com/scrm/2025/2025-22-19/ab77e3d0-8933-4746-94af-bb66f6e58d38/视频.mp4"
>
<template #play-icon>
<el-icon size="42" color="#fff" class="el-video__btn">
<VideoPlayer />
</el-icon>
</template>
</el-video>
</el-flex>
</template>
<script lang="ts" setup>
import { IconsVue } from 'element-plus-x'
const { VideoPlayer } = IconsVue
</script>
隐藏源代码
只读态
使用readonly
属性用于只展示封面不渲染video
,用户点击后使用全局一个video
来进行播放
关于尺寸问题,可以根据后端返回的尺寸大小,判断图片是否是横屏、竖屏、方形,然后编写对应的 css 类名,赋给el-video
组件,这样可以做到视觉统一的效果
尹

徐
尹

vue
<template>
<el-flex vertical>
<el-bubble shape="arrow" :content-style="{ padding: '4px' }">
<template #avatar>
<el-avatar style="background: rgb(191 127 78)"> 尹 </el-avatar>
</template>
<template #default>
<el-video
readonly
poster="https://realbot-oss.oss-accelerate.aliyuncs.com/scrm/2025/2025-05-20/16910ba6-0708-48d2-9693-27ea40e2cd30/1.jpg"
duration="1:56"
style="max-width: 180px"
:icon-props="{ color: 'rgba(255,255,255,0.7)' }"
@click="handleClick(0)"
/>
</template>
</el-bubble>
<el-bubble
shape="arrow"
placement="end"
:content-style="{ padding: '4px' }"
>
<template #avatar>
<el-avatar style="background: rgb(9 200 31)"> 徐 </el-avatar>
</template>
<template #default>
<el-video
readonly
poster="https://realbot-oss.oss-accelerate.aliyuncs.com/scrm/2025/2025-22-19/ab77e3d0-8933-4746-94af-bb66f6e58d38/视频.mp4?x-oss-process=video/snapshot,t_1000,f_jpg,m_fast"
duration="2:51"
style="max-width: 160px"
:icon-props="{ color: 'rgba(255,255,255,0.7)' }"
@click="handleClick(1)"
/>
</template>
</el-bubble>
<el-bubble shape="arrow" :content-style="{ padding: '4px' }">
<template #avatar>
<el-avatar style="background: rgb(191 127 78)"> 尹 </el-avatar>
</template>
<template #default>
<el-video
readonly
poster="https://realbot-oss.oss-accelerate.aliyuncs.com/scrm/2025/2025-05-20/c87f2d68-f318-4463-a61f-c4fc44b1f297/报纸墙可爱女孩白媗4K动漫壁纸_彼岸图网.jpg"
duration="8:23"
style="max-width: 250px"
:icon-props="{ color: 'rgba(255,255,255,0.7)' }"
@click="handleClick(0)"
/>
</template>
</el-bubble>
</el-flex>
</template>
<script lang="ts" setup>
import { previewVideo } from 'element-plus-x'
import type { VideoViewerProps } from 'element-plus-x'
const handleClick = (index) => {
previewVideo({
initialIndex: index,
urlList: [
{
src: 'https://realbot-oss.oss-accelerate.aliyuncs.com/scrm/2025/2025-05-21/659fa31d-dc87-4882-8be5-1fba8fb7e6ff/flower.mp4',
poster:
'https://realbot-oss.oss-accelerate.aliyuncs.com/scrm/2025/2025-05-21/659fa31d-dc87-4882-8be5-1fba8fb7e6ff/flower.mp4?x-oss-process=video/snapshot,t_1000,f_jpg,m_fast',
},
{
src: 'https://realbot-oss.oss-accelerate.aliyuncs.com/scrm/2025/2025-22-19/ab77e3d0-8933-4746-94af-bb66f6e58d38/视频.mp4',
poster:
'https://realbot-oss.oss-accelerate.aliyuncs.com/scrm/2025/2025-22-19/ab77e3d0-8933-4746-94af-bb66f6e58d38/视频.mp4?x-oss-process=video/snapshot,t_1000,f_jpg,m_fast',
style: {
maxWidth: '200px',
},
},
],
} as VideoViewerProps)
}
</script>
隐藏源代码
API
属性
属性名 | 说明 | 类型 | 默认值 |
---|---|---|---|
src | 视频地址 | String | - |
poster | 视频封面 | String | - |
duration | 时长,如果是数字内部会计算转换 | String|Number | - |
readonly | 只读态 | Boolean | false |
on-click | 点击封面的回调 | Function | - |
icon-props | ElIcon 组件属性 | Object | - |
poster-props | img 属性 | Object | - |
Slots
事件名 | 说明 |
---|---|
default | video 标签的子内容 |
poster | 封面内容 |
duration | 时长内容 |
play-icon | 播放按钮内容 |
Exposes
名称 | 详情 | 类型 |
---|---|---|
video | video 元素 | Object |