vue中el-upload 上传视频
时间: 2024-01-27 07:15:25 浏览: 336
vue结合el-upload实现腾讯云视频上传功能
以下是在Vue中使用el-upload上传视频的示例代码:
```html
<template>
<el-upload
class="upload-demo"
action="/upload"
:before-upload="beforeUpload"
:on-success="handleSuccess"
:on-error="handleError"
:file-list="fileList"
:limit="1"
:accept="videoAccept"
>
<el-button size="small" type="primary">点击上传视频</el-button>
</el-upload>
</template>
<script>
export default {
data() {
return {
fileList: [],
videoAccept: 'video/*'
};
},
methods: {
beforeUpload(file) {
const isVideo = file.type.startsWith('video/');
if (!isVideo) {
this.$message.error('请上传视频文件');
}
const isLt100M = file.size / 1024 / 1024 < 100;
if (!isLt100M) {
this.$message.error('视频大小不能超过100MB');
}
return isVideo && isLt100M;
},
handleSuccess(response, file, fileList) {
// 处理上传成功的逻辑
console.log(response);
},
handleError(error, file, fileList) {
// 处理上传失败的逻辑
console.log(error);
}
}
};
</script>
```
阅读全文