我正在处理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

Please check running code

Edit as per bounty

我必须使用"html到纸张"来完成这项工作.问题是,我无法为使用@media print的打印元素提供样式

  • 答案为ux.engineer是可以的,但由于安全问题,crome和firefox正在阻止它

Please check code sandbox例如,这里是我的完整代码,我试图给造型,但没有发生

  • html-to-print插件使用Windows.打开,这样当我点击打印时,它不会将样式带到新页面.
  • 这就是我被困的地方,为什么它不采用媒体风格,我怎么能在窗口上覆盖我的风格.打开

I was Using print-nb但由于某些安全原因,它无法在浏览器上运行this is what is says while using print-nb

推荐答案

不幸的是,您无法利用Vue的数据绑定来实现这mycurelabs/vue-html-to-paper mixin packageas stated here by the package author.

然而,我已经创建了一个解决方案,将这里使用的包切换到Power-kxLee/vue-print-nb directive.

这里有一个有效的例子:https://codesandbox.io/s/kind-hypatia-inutd

另外,在类似的软件包中进行 Select 有时可能会很棘手.人们应该判断回购协议的使用情况和活动统计数据,比如:首页上的使用、观看和开始,然后判断开放/关闭的问题和活动/关闭的拉取请求,然后进入Insights查看脉冲(1个月)和代码频率.

在这两者之间,我会 Select vue-print-nb,因为它更受欢迎,使用更积极.也因为I'd prefer using a directive over a mixin.

至于另一个答案,继续使用vue html为此目的 compose 论文将需要这种黑客解决方案...本指令开箱即用.

https://github.com/mycurelabs/vue-html-to-paper

https://github.com/Power-kxLee/vue-print-nb

Vue.js相关问答推荐

Vue CDN的html工作,但v—如果不工作

我需要在 nuxt2 上使用 /index 作为 url 的一部分

Vuetify右侧并排switch

传单 vue3 组件变体打开错误的标记 - 单击时弹出

过渡如何在 Vue JS 3 中的图像上工作?

vue3 ssr 不返回纯 html

VuetifyJS:如何摆脱 v-stepper 组件的提升?

在 VueJS 中存储图像的正确位置是什么 - 公共文件夹或assets文件夹?

使用 vue.js 的 axios 预检失败错误 301

查看 cli3 启用 CORS

在 Vuejs 中Watch观察 window.scrollY 的变化

VueJS + VueRouter:有条件地禁用路由

导入没有 .vue 扩展名的 *.vue 文件时出现以下错误?

如何在 Vue 3 中使用 SSR

动态注册本地 Vue.js 组件

Vue路由安全

npm run dev 和 npm run production 的区别

Vue组件如何命名

Vue.js 中的条件 依赖于props值?

Vue 3 组合 API 数据()函数