Vue-cli 中的打印功能(window.print)
print.js 的封装
export default {
initIframe(printOption) {
let printIframe = document.getElementById('easyPrintIframe');
if (!printIframe) {
printIframe = document.createElement('iframe');
printIframe.id = 'easyPrintIframe';
printIframe.style.position = 'fixed';
printIframe.style.width = '0';
printIframe.style.height = '0';
printIframe.style.top = '-100px';
if (window.location.hostname !== document.domain && navigator.userAgent.match(/msie/i)) {
printIframe.src =
'javascript:document.write("<head><script>document.domain="' + document.domain + '";</script></head><body></body>")';
}
document.body.appendChild(printIframe);
printIframe.onload = () => {
this.getStyle(printOption);
};
}else{
printIframe.contentDocument.body.innerHTML = '';
printIframe.contentDocument.head.innerHTML = '';
this.getStyle(printOption);
}
},
setValues () {
const inputs = document.querySelectorAll('input');