情景:点击按钮下载,调取websocket接口,将返回的res下载到电脑
问题:在网上找到一个下载方法后,下载的excl文件内容显示的是[object MessageEvent]
下面附上打印出来的res以及相关代码
downData(){
const that = this;
//调用封装的 websocket 请求方法
let wstUrl = "ws://" + location.host + "/ws" + this.wstUrl;
// 连接WebSocket
that.wstwebsocket = new WebSocket(wstUrl);
//实拍云量
that.wstwebsocket.onopen = function() {
//发送信息
that.wstwebsocket.send('1');
};
that.wstwebsocket.onmessage = function(res) {
console.log('val',res)
const content = res;
const blob = new Blob([content])
const fileName = that.wstUrl + '.xls'; //自定义下载文件的名字
const elink = document.createElement('a');
elink.download = fileName;
elink.style.display = 'none';
elink.href = URL.createObjectURL(blob);
document.body.appendChild(elink);
elink.click();
URL.revokeObjectURL(elink.href); // 释放URL 对象
document.body.removeChild(elink);
} ;
},
const content = res.data;
可以解决,但是下载的表格单元格格式可以设置吗