/**

=

=

=

=

=

=

=

=

=

=

=

=

=

=

=

=

=

=

=

=

=

=

=

*/

先说一下空白页,造成空白页的问题是因为打印页面开始的时候样式中设置了margin-top或者样式中包含margin-top属性,所以导致多出一页空白。

最后展示页面代码:

<!-- 根据id="printNN"去渲染打印页面 --> 
<div id="printNN" :key="key"
      style="height:600px;position:absolute;top:10000px;width:1100px;font-family:Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, Arial, sans-serif;color:black;-webkit-font-smoothing: antialiased;text-rendering: optimizeLegibility;font-weight: bold;">
<!-- 表格上方写入其他样式开始位置 
totalPage:总页数,
tableData总数据,
totalSize:每页大小
 表格中的materialName太长不会分行,设置white-space进行分行 
-->

      <div v-for="(n, index) in   totalPage  " :key="index" style="page-break-before:always;width:1100px;">

        <el-table :data="tableData.slice(index * totalSize, ((totalTable - ((index + 1) * totalSize)) > 0 ? (index + 1) * totalSize : totalTable))">
          <el-table-column label="序号" align="center" prop="index" width="60" />
          <el-table-column label="名称" align="center" prop="materialName">
            <template slot-scope="scope"><span v-html="scope.row.materialName"
                style="width: 100%; white-space: pre-wrap !important"></span></template>
          </el-table-column>
          <el-table-column label="单位" align="center" prop="unit" width="100" />
          <el-table-column label="单价" align="center" prop="price" width="110" />
          <el-table-column label="出库数量" align="center" prop="outQty" width="100" />
          <el-table-column label="总价" align="center" prop="cost" width="150" />
          <!-- <el-table-column label="备注" align="center" prop="remark" /> -->
        </el-table>
        <br />
        
      </div>
<!-- 表格下方写入其他样式开始位置 -->
    </div>

js代码

 printpage () {
        //发送请求
       Promise.all([]).then(_res => {
        //数据处理完成后(该处要设置tableData,totalTable,totalPage) 下面开始做打印
        // printNN与上面的id= printNN对应

        setTimeout(() => {
          document.body.innerHTML = document.getElementById("printNN").innerHTML; /* 改变页面内容 */
          window.print();
          document.body.innerHTML = "";
          location.reload(); /* 重新载入文档,复原页面内容 */
        }, 500);


      })


    },

GitHub 加速计划 / vu / vue
207.52 K
33.66 K
下载
vuejs/vue: 是一个用于构建用户界面的 JavaScript 框架,具有简洁的语法和丰富的组件库,可以用于开发单页面应用程序和多页面应用程序。
最近提交(Master分支:1 个月前 )
73486cb5 * chore: fix link broken Signed-off-by: snoppy <michaleli@foxmail.com> * Update packages/template-compiler/README.md [skip ci] --------- Signed-off-by: snoppy <michaleli@foxmail.com> Co-authored-by: Eduardo San Martin Morote <posva@users.noreply.github.com> 3 个月前
e428d891 Updated Browser Compatibility reference. The previous currently returns HTTP 404. 3 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐