1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| <script> const download = () => { let filename = ""; if (toutiao.value.type == 1){ filename = toutiao.value.pictures; }else { filename = toutiao.value.video; } downloadFile(filename).then((res)=>{ //创建一个URL let url = window.URL.createObjectURL(new Blob([res])) // 创建一个a标签 let link = document.createElement("a") // a标签不需要在页面显示 link.style.display = "none"; // a标签他的href设置为url link.href = url; link.setAttribute("download",filename) // 将a标签放入页面 document.body.appendChild(link) //模拟点击a标签的行为 link.click(); //将url和link所占用的资源释放 window.URL.revokeObjectURL(url) document.body.removeChild(link) Toast("下载成功!") }); } </script>
|