vue3+ts+ant下载方法的书写
话不多说 直接上代码
template
<a-button danger @click="editFun(record.id)">剪辑并下载</a-button>
<script setup lang="ts">
const editFun = async () => {
let params = {
id: state.videoId,
};
if (state.startSecond != 0 && state.endSecond != 0) {
params['clip'] = {
startSecond: state.startSecond,
endSecond: state.endSecond,
};
}
if (state.width != 0 && state.height != 0) {
params['resizer'] = {
width: state.width,
height: state.height,
};
}
if (state.format != '') {
params['transcoding'] = {
format: state.format,
};
}
let res: any = await videoApi.videoDown(params);
//videoApi.videoDown 在上传文章里api/video.ts 已写
// 创建一个下载链接并模拟点击以下载文件
const url = window.URL.createObjectURL(new Blob([res.data]));
const link: any = document.createElement('a');
link.href = url;
link.setAttribute(
'download',
decodeURIComponent(res.headers['content-disposition'].split('=')[1]),
); // 文件名
document.body.appendChild(link);
link.click();
link.parentNode.removeChild(link);
window.URL.revokeObjectURL(url);
};
</script>