vue 调用浏览器的打印时,如何自动设置好缩放比例?

新手上路,请多包涵

image.png
我是使用vue-easy-print插件来实现模太框内的打印。
模太框的代码如下:

<template>
  <div class="printDialog">
    <el-dialog
      :visible.sync="printvisible"
      :title="print_params.title"
      :width="print_params.width"
      :modal="print_params.modal"
      center
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :show-close="false"
      append-to-body
    >
      <el-scrollbar style="height: 70vh">
        <vueEasyPrint tableShow ref="easyPrint" v-if="chosenFlag == 1">
          <topEightTablePrint
            :topEight_params="print_params.checkData"
            :tableTitle="tableTitle"
          ></topEightTablePrint>
        </vueEasyPrint>
        <vueEasyPrint tableShow ref="easyPrint" v-if="chosenFlag == 2">
          <nonRoadMovePrint
            :nonRoadMove_params="print_params.checkData"
            :tableTitle="tableTitle"
          ></nonRoadMovePrint>
        </vueEasyPrint>
        <vueEasyPrint tableShow ref="easyPrint" v-if="chosenFlag == 3">
          <nonRoadDieselPrint
            :nonRoadDiesel_params="print_params.checkData"
            :tableTitle="tableTitle"
          ></nonRoadDieselPrint>
        </vueEasyPrint>
        <vueEasyPrint tableShow ref="easyPrint" v-if="chosenFlag == 4">
          <engineTablePrint
            :engine_params="print_params.checkData"
            :tableTitle="tableTitle"
          ></engineTablePrint>
        </vueEasyPrint>
      </el-scrollbar>
      <div style="text-align: center;margin-top:0.9375rem">
        <el-button @click="close_modal" type="primary">关闭</el-button>
        <el-button @click="print_check" type="primary">打印</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
    export default {
        methods: {
            print_check() {
                this.$refs.easyPrint.print();
            },
        }
    }
</script>

topEightTablePrint组件的style代码我添加了缩放比例设置:

@media print {
  html {
    zoom: 77%;
  }
}

但是都不起效果,麻烦帮忙看一下,可以怎么解决,谢谢!

阅读 8.3k
1 个回答

我这边这个问题终于解决了,我在想你这个缩放比例配置是不是没有在这里写,写在scoped里了,看了很多文章有篇貌似说写在scoped里会不起效

<style media="print">
@media print {
  html {
    zoom: 77%;
  }
}
</style>
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏