一、安装
npm install html2canvas --save
npm install print-js --save
<div class="operateArea boxSd setBtn" data-html2canvas-ignore :key="item.key">
<el-button v-if="lItem.btnType == 'print'" @click="openPrint()">{{ $t(lItem.label) }}</el-button>
</div>
<script setup>
import html2canvas from 'html2canvas';
import printJS from 'print-js'
function openPrint(){
proxy.$modal.msgSuccess(t('element255'), 2000)
setTimeout(()=>{
html2canvas(curPage.value, {
backgroundColor: '#ffffff',
useCORS: true,
windowHeight: document.body.scrollHeight,
y:window.pageYOffset
}).then((canvas) => {
const url = canvas.toDataURL()
printJS({
printable: url,
type: 'image',
style: `@media print { @page {size: auto; margin: 0; } body{margin:0 5px}}`,
documentTitle: '',
})
})
},100)
}
</script>