前端实现打印需求
利用window方法Window.print
const html = " " //html字符串,要打印的内容
const iframe: any = document.createElement('iframe')
iframe.setAttribute('style', 'display:none')
document.body.appendChild(iframe)
let title = document.title
document.title = titleText //自定义打印标题
let doc = iframe.contentWindow.document
doc.close()
iframe.contentWindow.focus()
doc.write(html)
iframe.contentWindow.print()
iframe.parentNode.removeChild(iframe)
document.title = title