代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<template>
<el-upload
multiple
action="http://192.168.1.8:3030/file/upload"
:auto-upload="false"
:show-file-list="false"
:on-change="handleChange"
>
<template #trigger>
<el-button type="primary" @click="folderMode(false)">上传文件</el-button>
<el-button type="primary" @click="folderMode(true)">上传文件夹</el-button>
</template>
</el-upload>
</template>
<script setup lang="ts">
import { reactive, onMounted, nextTick } from "vue";
import type { UploadFile, UploadFiles } from "element-plus";
const state = reactive({
uploadEle: null as Element | null,
uploadList: [],
});
const folderMode = (type: boolean) => {
if (state.uploadEle) {
state.uploadEle.webkitdirectory = type;
}
};
const handleChange = async (
uploadFile: UploadFile,
uploadFiles: UploadFiles
) => {
console.log(uploadFile, uploadFiles);
};
onMounted(() => {
nextTick(() => {
state.uploadEle = document.querySelector(".el-upload__input");
});
});
</script>
<style lang="less" scoped></style>

示例