【js】文件下载

  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();
            })
    }

 

posted @ 2023-05-17 13:16  维多利亚的巴黎世家  阅读(31)  评论(0)    收藏  举报