Element Plus el-upload 组件获取文件对象方法
<template>
<el-upload
ref="upload"
action="/upload"
@change="handleUploadChange"
>
<el-button>点击上传</el-button>
</el-upload>
</template>
<script>
export default {
methods: {
handleUploadChange(fileList) {
// 上传成功的文件列表
const uploadedFiles = fileList.filter(file => file.status === 'success');
// 获取第一个上传成功的文件对象
const file = uploadedFiles[0].raw;
console.log('文件对象:', file);
}
}
}
</script>
<p>注意,上传成功的文件对象是在文件上传成功后才会有,因此需要在 change 事件中进行处理。</p>
原文地址: https://www.cveoy.top/t/topic/ntBr 著作权归作者所有。请勿转载和采集!