uni.request({
url: '/api/coursePunch/export?courseId=' + _this.tableData.courseId,
method: "GET",
responseType:"arraybuffer",
header: {
"Accept": 'application/vnd.ms-excel;charset=utf-8',
"Content-type": 'application/vnd.ms-excel;charset=utf-8',
"token": _this.user.token,
},
success: (res) => {
uni.hideLoading();
console.log(res.data)
const blob = new Blob([res.data], {
type: 'application/vnd.ms-excel;charset=utf-8;'
})
let url = window.URL.createObjectURL(blob)
const fileName = '打卡记录.xlsx'
const elink = document.createElement('a')
elink.download = fileName
elink.style.display = 'none'
elink.href = window.URL.createObjectURL(blob)
document.body.appendChild(elink)
elink.click()
URL.revokeObjectURL(elink.href) // 释放URL 对象
document.body.removeChild(elink)
},
fail(e) {
uni.hideLoading();
uni.showToast({
title: e.data.msg,
icon: "none",
duration: 2000
});
}
});
这里的关键点就是 responseType:“arraybuffer”,很重要一代上就没有乱码了
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)