vue3 antdv upload上传文件

112 阅读1分钟
<a-upload v-model:file-list="fileList" accept:".pdf,.png" action="https://www.mocky.io/v2/5cc8019d300000980a055e76" :before-upload="beforeUpload" @change="handleChange" withCredentials > <a-button> <upload-outlined></upload-outlined> Upload png only </a-button> </a-upload>
const handleChange = ({ file, fileList }) => { 
    const fileList = file.fileList;
    fileList.forEach(item=>{
       if(item.status!== 'uploading'){
            files.value.push(item.response?.data) //files 传给后端的数据数组
        }
    })
 } }; 
const beforeUpload = file => {
 const isPNG = file.type === 'image/png'; 
 if (!isPNG) { message.error(`${file.name} is not a png file`); }
 return isPNG || Upload.LIST_IGNORE; 
 if(fileLists.value.length+fileList.length>5){ //fileLIsts.value upload绑定的值
    message.error("最多上传5个附件")
  }
};