1,把要打印的容器,定一个id
2.打印按钮加点击事件
printHandler(){ var printWrap=document.getElementById("print-wrap"); var newstr=printWrap.innerHTML; var oldstr=printWrap.innerHTML; document.body.innerHTML=newstr; window.print(); window.location.reload(); document.body.innerHTML=oldstr; return false; },
用reload的原因是回到之前的界面,功能都失效,刷新下就好
参考https://segmentfault.com/q/1010000011527757这个博客里面的回复,博客的方法,并没有用