@@ -36,6 +36,7 @@ After users upload picture, the thumbnail will be shown in list. The upload butt
36
36
<script lang="ts">
37
37
import { PlusOutlined } from ' @ant-design/icons-vue' ;
38
38
import { defineComponent , ref } from ' vue' ;
39
+ import type { UploadChangeParam , UploadProps } from ' ant-design-vue' ;
39
40
40
41
function getBase64(file : File ) {
41
42
return new Promise ((resolve , reject ) => {
@@ -46,22 +47,6 @@ function getBase64(file: File) {
46
47
});
47
48
}
48
49
49
- interface FileItem {
50
- uid: string ;
51
- name? : string ;
52
- status? : string ;
53
- response? : string ;
54
- percent? : number ;
55
- url? : string ;
56
- preview? : string ;
57
- originFileObj? : any ;
58
- }
59
-
60
- interface FileInfo {
61
- file: FileItem ;
62
- fileList: FileItem [];
63
- }
64
-
65
50
export default defineComponent ({
66
51
components: {
67
52
PlusOutlined ,
@@ -70,7 +55,7 @@ export default defineComponent({
70
55
const previewVisible = ref <boolean >(false );
71
56
const previewImage = ref <string | undefined >(' ' );
72
57
73
- const fileList = ref <FileItem [ ]>([
58
+ const fileList = ref <UploadProps [ ' fileList ' ]>([
74
59
{
75
60
uid: ' -1' ,
76
61
name: ' image.png' ,
@@ -105,14 +90,14 @@ export default defineComponent({
105
90
const handleCancel = () => {
106
91
previewVisible .value = false ;
107
92
};
108
- const handlePreview = async (file : FileItem ) => {
93
+ const handlePreview = async (file : UploadProps [ ' fileList ' ][ number ] ) => {
109
94
if (! file .url && ! file .preview ) {
110
95
file .preview = (await getBase64 (file .originFileObj )) as string ;
111
96
}
112
97
previewImage .value = file .url || file .preview ;
113
98
previewVisible .value = true ;
114
99
};
115
- const handleChange = ({ fileList : newFileList }: FileInfo ) => {
100
+ const handleChange = ({ fileList : newFileList }: UploadChangeParam ) => {
116
101
fileList .value = newFileList ;
117
102
};
118
103
0 commit comments