试过用windows.open,但会直接打开文件。使用又会自动添加.txt扩展名。怎么才能直接下载服务器上的原文件,且文件扩展名依旧为.cer
axios({
method: 'get',//请求方式
headers: {
'Content-Type': 'application/x-x509-ca-cert',
},
url: "../.cer",//请求路径
responseType: 'blob'
}).then(res => {
const blob = new Blob([res.data], {
type: 'application/x-x509-ca-cert;charset=utf-8',//设置扩展名
});
const objectUrl = URL.createObjectURL(blob);
const link = document.createElement('a');//我们用模拟q标签点击事件
const fname = name; //下载文件的名字
link.href = objectUrl;
link.setAttribute('download', fname);
document.body.appendChild(link);
/**
* 在这期间,我们可以做自己界面的反应逻辑
**/
link.click();//点击
document.body.removeChild(link); // 下载完成移除元素
window.URL.revokeObjectURL(URL); // 释放掉blob对象
})
直接下载下来不行吗 啊,标签 iframe、form都可以
<a href="filename.cer">下载</a>
如果浏览器直接打开加个mime类型试试application/x-x509-ca-cert