【js】文件下载

发布时间 2023-05-17 13:19:59作者: 维多利亚的巴黎世家
  const donwLoadFn = (arr) => {
        if (arr.length <= 0) return
        const fullUrl = `http://192.168.2.50:9803${arr[0]?.filePath}`
        fetch(fullUrl)
            .then(res => res.blob())
            .then(blob => {
                const a = document.createElement("a");
                const objectUrl = window.URL.createObjectURL(blob);
                a.download = arr[0]?.fileName;
                a.href = objectUrl;
                a.click();
                window.URL.revokeObjectURL(objectUrl);
                a.remove();
            })
    }