Newer
Older
KaiFengPC / src / views / preassess / targetManage / upload.vue
@zhangdeliang zhangdeliang on 23 May 966 bytes 初始化项目
  1. <template>
  2. <el-upload class="upload" :action="uploadConfig.url" :before-upload="beforeUpload" :on-success="onSuccess" :on-error="onError">
  3. <slot></slot>
  4. </el-upload>
  5. </template>
  6.  
  7. <script setup>
  8. const props = defineProps({
  9. uploadConfig: {
  10. type: Object,
  11. default: () => {},
  12. },
  13. });
  14.  
  15. const emit = defineEmits(['success']);
  16.  
  17. const { uploadConfig } = props;
  18.  
  19. const beforeUpload = rawFile => {
  20. console.log(rawFile);
  21. if(rawFile.name.length > 50) {
  22. proxy.$modal.msgError(`文件名称过长(50个字符以内),请先修改再上传!`);
  23. return false
  24. }
  25. return true;
  26. };
  27.  
  28. const onSuccess = (response, uploadFile, uploadFiles) => {
  29. console.log(response, uploadFile, uploadFiles);
  30. emit('success');
  31. };
  32.  
  33. const onError = (error, uploadFile, uploadFiles) => {
  34. console.log(error, uploadFile, uploadFiles);
  35. };
  36. </script>
  37.  
  38. <style lang="scss" scoped>
  39. .upload {
  40. display: inline-block;
  41. :deep(.el-upload-list) {
  42. display: none;
  43. }
  44. }
  45. </style>