粘贴上传图片
<div v-on:paste="handlePaste">paste</div>
handlePaste(event) {
let data = event.clipboardData;
try {
let items = data && data.items;
if (items && items.length) {
for (let i = 0; i < items.length; i++) {
// 获取图片对象
if (items[i].type.indexOf('image') !== -1) {
const file = items[i].getAsFile();
let fd = new FormData();
fd.append('file', file);
uploadPicture(fd).then(res => {
const resData = res.data.data;
});
}
}
}
} catch (error) {
console.log('error:', error);
}
},
标签:items,data,let,file,error,fd,上传,粘贴,图片
From: https://www.cnblogs.com/new-bee-2023/p/17562936.html