页面:
<a-button type="primary" @click="printAppointment">打印</a-button>
//v-show="false" 为false是因为页面不需要显示iframe内容(只需要打印)
<iframe v-show="false" id="appointmentDetailPrintIframe"></iframe>
方法:
printAppointment(){
//直接将接口赋值iframe src 中 放到线上会导致iframe跨域问题。
let iframe = document.getElementById('appointmentDetailPrintIframe')
let iframedoc = iframe.contentDocument || iframe.contentWindow.document;
//getHisPerson是封装的axios GET 请求
//这里是请求接口拿到返回的html 然后给iframe 实现曲线救国。
getHisPerson('请求需要打印的html页面接口',{参数}).then(res=>{
console.log("打印挂号单获取的::",res)
iframedoc.body.innerHTML = res;
iframe.contentWindow.focus()
iframe.contentWindow.print();
})
}
iframe调用打印 线上跨域,曲线救国!!!
于 2022-11-07 16:47:04 首次发布