vue - 再次点击路由不走 created 和 mounted 的解决
2020-05-17 •
1 条评论
activated () {
// TO DO
},
import { fileDownloadList, fileDownload } from "@/api/file/download";
fileDownload(row.fileId).then(
response => {
console.log(response)
const filename = decodeURI(response.headers['content-disposition'].split(';')[1].split('=')[1]);
let blob = new Blob([response.data],{
type: response.headers['content-type']
});
var blobURL = window.URL.createObjectURL(blob)
var tempLink = document.createElement('a')
tempLink.style.display = 'none'
tempLink.href = blobURL
tempLink.setAttribute('download', filename)
if (typeof tempLink.download === 'undefined') {
tempLink.setAttribute('target', '_blank')
}
document.body.appendChild(tempLink)
tempLink.click()
document.body.removeChild(tempLink)
window.URL.revokeObjectURL(blobURL)
}
).catch(err => {
console.log(err);
});
终于下载下来了,但是万万没想到啊,除了txt格式的打开的内容是正常的,其他格式如docx打开的却是乱码。
使用如下方法可以解决文件内容乱码问题:
<el-table-column
label="序号"
type="index"
width="50"
align="center">
<template scope="scope">
<span>{{(page - 1) * pageSize + scope.$index + 1}}</span>
</template>
</el-table-column>