我想使用vue.js进行打印。
下面是我的代码示例。是可行的,但有时会显示打印对话框
在文档完全加载之前
let myWindow = window.open("", "MsgWindow");
let receiptHtml = app.$refs.receipt.innerHTML; // html to print
waitLoadingAndPrint();
function waitLoadingAndPrint() {
if (myWindow && !myWindow.closed && myWindow.document ) {
myWindow.document.write(receiptHtml);
myWindow.print();
myWindow.close();
} else if (myWindow && !myWindow.closed) {
setTimeout(waitLoadingAndPrint, 30);
}
}
答案 0 :(得分:0)
我只是使用iframe改变了方式
let myWindow = window.frames["printf"];
let printScript = '<script>if(typeof printCopies === "undefined"){ let printCopies = 0;} printCopies = '+ app.printCopies + '; function printDocument(){if(printCopies > 0){ for(let i= printCopies ; i>= 0; i--){ window.print(); } } else{ window.print();}} </script>';
myWindow.document.write( printScript + '<body onload="printDocument()">'+receiptHtml '</body>' );