element下载文件模拟a标签点击,接收blob二进制文件

downloadFileMethod(file){
    let that = this;
    event.preventDefault();
    axios({
        method: 'get',
        url: that.downloadCommonUrl+'?id='+file.id,
        responseType: 'blob'
    }).then(data => {
        let balo = data.data;
        if(balo.length=0){
            return;
        }
        let url = window.URL.createObjectURL(new Blob([balo]))
        let link = document.createElement('a')
        link.style.display = 'none'
        link.href = url
        link.setAttribute('download', file.name)
        document.body.appendChild(link)
        link.click()
    })
}

element upload组件调用::on-preview="downloadFileMethod"

猜你喜欢

转载自blog.csdn.net/weixin_39308542/article/details/105435079