ajax下载

<body>
<button id="btn">下载</button>
</body>
<script>
    btn.onclick=()=>{
        fetch("./download.pdf")
            .then(r=>{
                return r.blob()
            }).then(res=>{
                blob = URL.createObjectURL(res)
                let a = document.createElement("a")
                a.href = blob
                a.download = "PDF"
        document.body.appendChild(a)
        a.click()
        document.body.removeChild(a)
        URL.revokeObjectURL(blob)
        })
    }
</script>
posted @ 2020-01-19 15:14  这都没什么  阅读(115)  评论(0编辑  收藏  举报