<template> <el-upload class="upload" action="/prod-api/system/upload" :headers="uploadHeader" :before-upload="beforeUpload" :on-success="onSuccess" :on-error="onError" :disabled="disabled" :file-list="fileList" > <slot></slot> </el-upload> </template> <script setup> import { getToken } from "@/utils/auth" const props = defineProps({ disabled: { type: Boolean, default: false }, fileList: { type: Array, default: () => [] } }) const emit = defineEmits(['success']) const { disabled } = props const uploadHeader = ref({ Authorization: "Bearer " + getToken(), }); const beforeUpload = (rawFile) => { console.log(rawFile) return true } const onSuccess = (response, uploadFile, uploadFiles) => { const { extension, name, originalName, refField, refType, size, url } = response.data const file = { extension, name, originalName, refField, refType, size, url } emit('success', file) } const onError = (error, uploadFile, uploadFiles) => { console.log(error, uploadFile, uploadFiles) } </script> <style lang="scss" scoped> .upload { display: inline-block; ::v-deep(.el-upload-list) { display: none; } } </style>