You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ant-design-vue/components/upload/demo/preview-file.vue

50 lines
1.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<docs>
---
order: 9
title:
zh-CN: 自定义预览
en-US: Customize preview file
---
## zh-CN
自定义本地预览用于处理非图片格式文件例如视频文件
## en-US
Customize local preview. Can handle with non-image format files such as video.
</docs>
<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" setup>
import { ref } from 'vue';
import { UploadOutlined } from '@ant-design/icons-vue';
import type { UploadProps } from 'ant-design-vue';
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;
};
const fileList = ref([]);
</script>