<div v-if="IsPrint" style="margin: 0 auto;" class="print" v-html="printCode" ref="print"></div>
<el-button @click="printPage" >打印</el-button>
printPage() {
const printContent = this.$refs.print;
const printWindow = window.open('', '_blank');
const htmlContent = `
<html>
<head>
<title>打印11</title>
<style>
@media print {
/* 打印页的CSS样式 */
* {
padding: 0;
margin: 0;
}
ul {
text-decoration: none;
list-style-type: none;
text-decoration: underline;
font-weight: bold;
}
}
</style>
</head>
<body>
${printContent.innerHTML}
</body>
</html>
`;
printWindow.document.write(htmlContent);
printWindow.document.close();
printWindow.onload = () => {
printWindow.print();
printWindow.close();
};
},
vue实现打印指定div的功能
于 2023-08-22 15:29:22 首次发布