我正在处理HTML表格,并使用html-to-paper
英寸vue将表格打印到打印机上.js,我正在做的是点击add创建一个新行,然后点击print,我试图打印表格,但它不获取任何数据,只显示空单元格
Code App.vue
<template>
<div id="app">
<button type="button" @click="btnOnClick">Add</button>
<div id="printMe">
<table class="table table-striped table-hover table-bordered mainTable" id="Table">
<thead>
<tr>
<th class="itemName">Item Name</th>
<th>Quantity</th>
<th>Selling Price</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
<tr v-for="(tableData, k) in tableDatas" :key="k">
<td>
<input class="form-control" readonly v-model="tableData.itemname" />
</td>
<td>
<input class="form-control text-right" type="text" min="0" step=".01" v-model="tableData.quantity" v-on:keyup="calculateQty(tableData)" />
</td>
<td>
<input class="form-control text-right" type="text" min="0" step=".01" v-model="tableData.sellingprice" v-on:keyup="calculateSPrice(tableData)" />
</td>
<td>
<input readonly class="form-control text-right" type="text" min="0" step=".01" v-model="tableData.amount" />
</td>
</tr>
</tbody>
</table>
</div>
<button @click="print">Print</button>
</div>
</template>
<script>
export default {
data() {
return {
tableDatas: []
}
},
methods: {
btnOnClick(v) {
this.tableDatas.push({
itemname: "item",
quantity: 1,
sellingprice: 55,
amount: 55
});
},
print() {
this.$htmlToPaper('printMe');
}
}
};
</script>
<style>
</style>
main.js
import Vue from "vue";
import App from "./App.vue";
import VueHtmlToPaper from "vue-html-to-paper";
Vue.config.productionTip = false;
Vue.use(VueHtmlToPaper);
new Vue({
render: h => h(App)
}).$mount("#app");
here the working code in codesandbox
Edit as per bounty
我必须使用"html到纸张"来完成这项工作.问题是,我无法为使用@media print
的打印元素提供样式
- 答案为
ux.engineer
是可以的,但由于安全问题,crome和firefox正在阻止它
Please check code sandbox例如,这里是我的完整代码,我试图给造型,但没有发生
-
html-to-print
插件使用Windows.打开,这样当我点击打印时,它不会将样式带到新页面. - 这就是我被困的地方,为什么它不采用媒体风格,我怎么能在窗口上覆盖我的风格.打开