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