- <template>
- <el-upload class="upload" :action="uploadConfig.url" :before-upload="beforeUpload" :on-success="onSuccess" :on-error="onError">
- <slot></slot>
- </el-upload>
- </template>
-
- <script setup>
- const props = defineProps({
- uploadConfig: {
- type: Object,
- default: () => {},
- },
- });
-
- const emit = defineEmits(['success']);
-
- const { uploadConfig } = props;
-
- const beforeUpload = rawFile => {
- console.log(rawFile);
- if(rawFile.name.length > 50) {
- proxy.$modal.msgError(`文件名称过长(50个字符以内),请先修改再上传!`);
- return false
- }
- return true;
- };
-
- const onSuccess = (response, uploadFile, uploadFiles) => {
- console.log(response, uploadFile, uploadFiles);
- emit('success');
- };
-
- const onError = (error, uploadFile, uploadFiles) => {
- console.log(error, uploadFile, uploadFiles);
- };
- </script>
-
- <style lang="scss" scoped>
- .upload {
- display: inline-block;
- :deep(.el-upload-list) {
- display: none;
- }
- }
- </style>