<div>
<div id="printMe">
<div class="goodsStyle demo-flex">
<span class="orderStyle goodsInfos" style="font-size:26px;color: #000;font-weight: 600;">{{goodsInfo.productName}}</span>
</div>
</div>
<div style="text-align: center;margin-top: 20px">
<el-button size="small" ref="btn" type="primary" class="printObjDy" @click="handleprint(printObj)" v-print="printObj">打 印</el-button>
</div>
</div>
export default {
name: "index",
data() {
return {
printObj: {
id: "printMe",
popTitle: '订单',
extraCss: '',
extraHead: '<meta http-equiv="Content-Language" content="zh-cn"/>'
}
}
},
mounted() {
setTimeout(() => {
this.$refs.btn.$el.click()
}, 1000)
},
created() {
this.handleprint();
},
methods: {
handleprint(val) {
console.log(val)
console.log(111)
},
}
}
<div id="printDiv">打印的内容</div>
<button v-print="'#printDiv'">打印</button>