更新记录
1.0.0(2026-04-14)
下载此版本
初始化
平台兼容性
uni-app(4.85)
| Vue2 |
Vue3 |
Chrome |
Safari |
app-vue |
app-nvue |
Android |
iOS |
鸿蒙 |
| √ |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
| 微信小程序 |
支付宝小程序 |
抖音小程序 |
百度小程序 |
快手小程序 |
京东小程序 |
鸿蒙元服务 |
QQ小程序 |
飞书小程序 |
小红书小程序 |
快应用-华为 |
快应用-联盟 |
| √ |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
- |
√ |
√ |
uni-app x(4.85)
| Chrome |
Safari |
Android |
iOS |
鸿蒙 |
微信小程序 |
| - |
- |
- |
- |
- |
- |
简介
dl-upload-imageVideo 是一个基于 uni-app 的通用图片视频选择器组件,支持从相册或相机选择图片和视频。它提供底部弹窗样式的选择菜单,内置视频预览功能,并允许外部通过 props 自定义按钮文字和样式。组件兼容 Vue 2 和 Vue 3。
平台兼容性
| 平台 |
支持情况 |
| H5 |
✅ |
| 微信小程序 |
✅ |
| App (Vue) |
✅ |
| 支付宝/抖音小程序 |
✅ |
Props 属性
| 属性名 |
类型 |
默认值 |
说明 |
imgButtonText |
String |
'图片' |
图片按钮显示的文字 |
videoButtonText |
String |
'视频' |
视频按钮显示的文字 |
imgButtonStyle |
Object |
{} |
图片按钮的自定义样式对象(如 { backgroundColor: '#f00', color: '#fff' }) |
videoButtonStyle |
Object |
{} |
视频按钮的自定义样式对象 |
maxCount |
Number |
1 |
允许选择的最大文件数量(仅对图片有效,视频每次只能选1个) |
showImgBtn |
Boolean |
true |
是否展示上传图片按钮 |
showVideoBtn |
Boolean |
true |
是否展示上传视频按钮 |
方法(通过 ref 调用)
| 方法名 |
参数 |
说明 |
openFileFn(fn) |
fn: Function |
打开文件选择弹窗。选择完成后执行回调 fn(result),result 为 { tempFiles } 对象,其中每个文件包含 path、fileType 等字段。 |
closeFileFn() |
无 |
关闭文件选择弹窗。 |
seeVideo(path) |
path: String |
打开视频预览弹窗,预览指定路径的视频。只测试过h5和安卓,其他平台如果不支持就只能自己写了 |
closeVideoPopup() |
无 |
关闭视频预览弹窗。 |
使用示例
1. 基础用法
<template>
<view>
<button @click="pickFile">选择文件</button>
<button @click="previewVideo">预览示例视频</button>
<uploadImageVideo ref="uploadImageVideoRef" />
</view>
</template>
<script>
import uploadImageVideo from '@/uni_modules/dl-upload-imageVideo/components/dl-upload-imageVideo/dl-upload-imageVideo.vue'
export default {
components: { uploadImageVideo },
data:{
srcArr:[]
},
methods: {
pickFile() {
this.$refs.uploadImageVideoRef.openFileFn((result) => {
// 处理上传等操作
result.tempFiles.forEach(item=>{
this.srcArr.push(item.tempFilePath)
})
})
},
previewVideo() {
// 传入一个视频文件路径(可以是本地临时路径或网络URL)
this.$refs.uploadImageVideoRef.seeVideo(this.srcArr[0])
}
}
}
</script>