likes
comments
collection
share

a标签下载的两种方法

作者站长头像
站长
· 阅读数 46

1、<a href="/files/文件.zip">下载1</a>

2、

<div @click="download">下载2</div>

download(){
    let url = '/files/文件.zip'
    let filename = '下载的文件名称'
    return fetch(url).then(res => res.blob().then(blob => {
        let a = document.createElement('a');
        let url = window.URL.createObjectURL(blob);
        console.log(url);
        a.href = url;
        a.download = filename;
        a.click();
        window.URL.revokeObjectURL(url);
    }))
}
转载自:https://segmentfault.com/a/1190000041600899
评论
请登录