- 技术栈:vue2
- 需求:点击按钮下载文件或图片(绝对路径)
<el-table-column fixed="right" label="操作">
<template slot-scope="scope">
<el-button size="mini" type="text" icon="el-icon-download" @click="onDownloadDriver(scope.row)">
下载
</el-button>
</template>
</el-table-column>
onDownloadDriver(row) {
let link = document.createElement("a");
let url = row.attachment;
console.log('url', url);
fetch(url)
.then((res) => res.blob())
.then((blob) => {
link.href = URL.createObjectURL(blob);
console.log(link.href);
link.download = "";
document.body.appendChild(link);
link.click();
link.remove()
});
},