一.a标签完成
二.js实现下载
const a = document.createElement('a');
a.setAttribute('href', '文件链接'); //a.href='文件链接'
a.setAttribute('download', '文件名'); //a.download='文件名'
a.click();
三.js中ajax实现音频或者视频不跳转进行文件下载
写代码的思路
先请求音频的链接,再把返回值转换成二进制,再根据他二进制对象生成新链接,再创建a标签,点击a标签
//这是vue里面的写的普通页面也差不多
this.$axios({
method: 'get',
url: row.src,
responseType: 'blob' //这个不能少,让response二进制形式,如果你按照网上教程不设置这个将返回值进行BLOB([])进行处理可能会出现解析错误
}).then(response => {
const href = URL.createObjectURL(response.data); //根据二进制对象创造新的链接
const a = document.createElement('a');
a.setAttribute('href', href);
a.setAttribute('download', row