<template>
<div>
<a-upload
v-model:file-list="fileList"
list-type="picture"
action="//jsonplaceholder.typicode.com/posts/"
:preview-file="previewFile"
>
<a-button>
<upload-outlined></upload-outlined>
Upload
</a-button>
</a-upload>
</div>
</template>
<script lang="ts">
import { UploadOutlined } from '@ant-design/icons-vue';
import { defineComponent, ref } from 'vue';
import type { UploadProps } from 'ant-design-vue';
export default defineComponent({
components: {
UploadOutlined,
},
setup() {
const previewFile: UploadProps['previewFile'] = async file => {
console.log('Your upload file:', file);
// Your process logic. Here we just mock to the same file
const res = await fetch('https://next.json-generator.com/api/json/get/4ytyBoLK8', {
method: 'POST',
body: file,
});
const { thumbnail } = await res.json();
return thumbnail;
};
return {
previewFile,
fileList: ref([]),
};
},
});
</script>
ant-file预览
最新推荐文章于 2024-05-22 10:27:27 发布