如何替换blob案例的URL.createObjectURL()



我有下面的函数,并且使用了不推荐使用的URL.createObjectURL((方法:

const downloadExceptionFile = async () => {
const resp = await getExceptionFile();
const link = document.createElement('a');
link.setAttribute('download', 'excecoes.xlsx');
link.href = URL.createObjectURL(new Blob([resp.data]));
document.body.appendChild(link);
link.click();
link.remove();
};

我正在使用react,我尝试使用HTMLMediaElement.srcObject文档中建议的this.srcObjectthis.src,但是,我只是遇到了一个未定义的错误。

既然此方法已弃用,我如何替换URL.createObjectURL()

长话短说:

您不需要更改该代码,因为URL.createObjectURL()没有被弃用。

创建一个对象URL以附加到媒体元素(例如<video>(的具体用例是,为此您应该使用.srcObject

最新更新