实现 浏览器自带打印功能
首先 需要后端返回一个数据流
然后使用 方法 把数据流转换
getObjectURL(file) {
let url = null;
if (window.createObjectURL != undefined) {
// basic
url = window.createObjectURL(file);
} else if (window.webkitURL != undefined) {
// webkit or chrome
try {
url = window.webkitURL.createObjectURL(file);
} catch (error) {}
} else if (window.URL != undefined) {
// mozilla(firefox)
try {
url = window.URL.createObjectURL(file);
} catch (error) {}
}
return url;
},
然后在浏览器 中打开 此 url
const print = this.getObjectURL(res);
window.open(print);