94 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Vue
		
	
	
			
		
		
	
	
			94 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Vue
		
	
	
| <docs>
 | |
| ---
 | |
| order: 0
 | |
| title:
 | |
|   zh-CN: 自定义上传列表
 | |
|   en-US: Custom Render
 | |
| ---
 | |
| 
 | |
| ## zh-CN
 | |
| 
 | |
| 使用 `itemRender` 插槽进行完全自定义列表
 | |
| 
 | |
| ## en-US
 | |
| 
 | |
| Custom render by using `itemRender` slot.
 | |
| </docs>
 | |
| 
 | |
| <template>
 | |
|   <a-upload
 | |
|     v-model:file-list="fileList"
 | |
|     name="file"
 | |
|     action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
 | |
|     :headers="headers"
 | |
|     @change="handleChange"
 | |
|   >
 | |
|     <a-button>
 | |
|       <upload-outlined></upload-outlined>
 | |
|       Click to Upload
 | |
|     </a-button>
 | |
|     <template #itemRender="{ file, actions }">
 | |
|       <a-space>
 | |
|         <span :style="file.status === 'error' ? 'color: red' : ''">{{ file.name }}</span>
 | |
|         <a href="javascript:;" @click="actions.download">download</a>
 | |
|         <a href="javascript:;" @click="actions.remove">delete</a>
 | |
|       </a-space>
 | |
|     </template>
 | |
|   </a-upload>
 | |
| </template>
 | |
| <script lang="ts">
 | |
| import { message } from 'ant-design-vue';
 | |
| import { UploadOutlined } from '@ant-design/icons-vue';
 | |
| import { defineComponent, ref } from 'vue';
 | |
| import type { UploadChangeParam, UploadProps } from 'ant-design-vue';
 | |
| 
 | |
| export default defineComponent({
 | |
|   components: {
 | |
|     UploadOutlined,
 | |
|   },
 | |
|   setup() {
 | |
|     const handleChange = (info: UploadChangeParam) => {
 | |
|       if (info.file.status !== 'uploading') {
 | |
|         console.log(info.file, info.fileList);
 | |
|       }
 | |
|       if (info.file.status === 'done') {
 | |
|         message.success(`${info.file.name} file uploaded successfully`);
 | |
|       } else if (info.file.status === 'error') {
 | |
|         message.error(`${info.file.name} file upload failed.`);
 | |
|       }
 | |
|     };
 | |
| 
 | |
|     const fileList = ref<UploadProps['fileList']>([
 | |
|       {
 | |
|         uid: '-1',
 | |
|         name: 'xxx.png',
 | |
|         status: 'done',
 | |
|         url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
 | |
|         thumbUrl: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
 | |
|       },
 | |
|       {
 | |
|         uid: '-2',
 | |
|         name: 'yyy.png',
 | |
|         status: 'done',
 | |
|         url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
 | |
|         thumbUrl: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
 | |
|       },
 | |
|       {
 | |
|         uid: '3',
 | |
|         name: 'zzz.png',
 | |
|         status: 'error',
 | |
|         response: 'Server Error 500', // custom error message to show
 | |
|         url: 'http://www.baidu.com/zzz.png',
 | |
|       },
 | |
|     ]);
 | |
|     return {
 | |
|       fileList,
 | |
|       headers: {
 | |
|         authorization: 'authorization-text',
 | |
|       },
 | |
|       handleChange,
 | |
|     };
 | |
|   },
 | |
| });
 | |
| </script>
 |