转换函数
const changeBlob=(url)=> {
return new Promise((resolve) => {
const xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.responseType = "blob";
xhr.onload = () => {
if (xhr.status === 200) {
resolve(xhr.response);
}
};
xhr.send();
});
}
调用函数
changeBlob(url).then((res) => {
var nameArr = url.split("/");
const files = new File([res], nameArr[nameArr.length - 1], {
type: res.type,
});
ruleForm.file = files
});