vue中的vue-print-nb如何实现页面打印

目录
  • 安装
  • 在main.js中全局引入
  • 页面中使用

安装

npm install vue-print-nb --save

在main.js中全局引入

import Print from 'vue-print-nb'
Vue.use(Print);

页面中使用

备注:只会打印id=printMe内的网页

<template>
  <div class="table">
    <div class="tableList">
      <div id="printMe">
        <div class="title">打印模板</div>
        <div class="content-table-three">
          <div class="table-name-three">XXXX</div>
          <div class="table-info-three">{{ list.fromName }}</div>
          <div class="table-name-three">XXXX</div>
          <div class="table-info-three">{{ list.fromIdCard }}</div>
          <div class="table-name-three">XXXX</div>
          <div class="table-info-three">{{ list.fromPhone }}</div>
        </div>
        <div class="content-table-three">
          <div class="table-name-three">XXXX</div>
          <div class="table-info-three">{{ list.fromName }}</div>
          <div class="table-name-three"XXXX</div>
          <div class="table-info-three">{{ list.fromIdCard }}</div>
          <div class="table-name-three">XXXX</div>
          <div class="table-info-three">{{ list.fromPhone }}</div>
        </div>
        <div class="content-table-two">
          <div class="table-name-two">XXXX</div>
          <div class="table-info-two">{{ list.reason }}</div>
          <div class="table-name-two">XXXX</div>
          <div class="table-info-two">{{ list.reason }}</div>
        </div>
        <div class="content-table-one">
          <div class="table-name-one">XXXX</div>
          <div class="table-info-one">{{ list.reason }}</div>
        </div>
        <div class="content-table-one">
          <div class="table-name-one">XXXX</div>
          <div class="table-info-one">{{ list.reason }}</div>
        </div>
        <div class="content-table-img">
          <div class="table-name-one">XXXX</div>
          <div class="table-info-img">
            <div class="imgsrc">
              <img
                v-if="list.img"
                :src="list.img"
              />
            </div>
          </div>
        </div>
        <div class="content-table-img">
          <div class="table-name-one">XXXX</div>
          <div class="table-info-img">
            <div class="imgsrc">
              <img
                v-if="list.img"
                :src="list.img"
              />
            </div>
          </div>
        </div>
      </div>
      <div  class="table-btn">
        <Button type="info" v-print="printObj" class="btn-no">打印</Button>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "printInfo",
  data() {
    return {
      list:[],
      printObj: {
        id: "printMe",
        popTitle: "打印模板",
        extraHead: '<meta http-equiv="Content-Language"content="zh-cn"/>',
      },
    };
  },
  methods: {},
  computed: {},
  created() { },
};
</script>
<style   scoped>
.table {
  width: 100%;
  height: 100vh;
  overflow-y: scroll;
}
.tableList {
  width: 900px;
  margin: auto;
  margin-top: 20px;
}
.title {
  font-size: 20px;
  width: 100%;
  text-align: center;
}
.table-name-three,
.table-info-three {
  border: 0.55px solid;
  width: 16.7%;
}
.table-name-two,
.table-info-two {
  border: 0.55px solid;
  width: 25%;
  line-height: 100px;
  text-align: center;
}
.table-info-img {
  border: 0.55px solid;
  width: 75%;
}
.table-info-one {
  border: 0.55px solid;
  width: 75%;
}
.table-name-one {
  border: 0.55px solid;
  width: 25%;
}
.content-table-one,
.content-table-two,
.content-table-three {
  display: flex;
  height: 100px;
  width: 100%;
  line-height: 100px;
  text-align: center;
}
.content-table-img {
  display: flex;
  height: 100px;
  width: 100%;
  line-height: 100px;
  text-align: center;
}
img {
  max-width: 100%;
  height: 100%;
  background-size: 100%;
  background-repeat: no-repeat;
}
.imgsrc {
  width: 90%;
  margin: auto;
  height: 90%;
  margin-top: 5px;
}
.table-btn {
  margin-top: 20px;
  display: flex;
  justify-content: space-evenly;
  align-items: center;
  align-content: center;
}
</style>

以上为个人经验,希望能给大家一个参考,也希望大家多多支持我们。

(0)

相关推荐

  • vue打印插件vue-print-nb的实现代码

    1.引入插件npm install vue-print-nb --save 在main.js中引入 import Print from 'vue-print-nb'Vue.use(Print) 2.html代码 <div class="box"> <div id="printTest" class="upTable"> <table> <tr> <td class="title&qu

  • VUE如何利用vue-print-nb实现打印功能详解

    目录 一.安装vue-print-nb 二.引入Vue项目 三.参数说明 四.应用 五.注意点 补充:空白页的解决方法 总结 一.安装vue-print-nb 没有什么前提要求,直接安装即可,但因为Vue2.0和Vue3.0有着不同的用法,因此需要安装的版本也不同,各位看官自行取舍. Vue2.0版本安装方法: npm install vue-print-nb --save Vue3.0版本安装方法: npm install vue3-print-nb --save 二.引入Vue项目 Vue2

  • Vue中通过Vue.extend动态创建实例的方法

    在Vue中,如果我们想要动态地来控制一个组件的显示和隐藏,比如通过点击按钮显示一个对话框或者弹出一条信息.我们通常会提前写好这个组件,然后通过v-if = "show"来控制它的显示隐藏.如下所示: <div> <button @click = "show = !show">弹出</button> <span v-if = "show">这是一条通过按钮控制显示隐藏的信息</span>

  • vue中实现点击按钮滚动到页面对应位置的方法(使用c3平滑属性实现)

    vue项目中,需要实现点击对应按钮,滚动到对应页面位置,下面分享一个简单实用的方法 原文地址 http://www.sharedblog.cn/?post=205 <template> <div class="box"> <div class="btn"> <span @click="Submit(1)">按钮一</span> <span @click="Submit(2

  • Vue中的.vue文件的使用方式

    目录 定义.vue文件 引用.vue文件 使用render函数 什么是.vue文件,它的作用是什么 需要安装vue-loader npm i vue-loader vue-template-complier -D 然后在配置文件中新增匹配规则 {test:/\.vue$/,use:'vue-loader'} 定义.vue文件 <template> <!--这里定义html模板--> </template> <script> //这里定义js //在这里导入文

  • vue中内嵌iframe的src更新页面未刷新问题及解决

    目录 vue内嵌iframe的src更新页面未刷新 原因 解决 iframe的src指向的内容不刷新的解决方法之一 总结 vue内嵌iframe的src更新页面未刷新 vue中,系统使用iframe内嵌了其他系统的页面,iframe的src修改了,但是iframe内部页面内容未更新,也未请求接口. 原因 iframe的src中如果带hash #,src改变是不会刷新的. 解决 方式一:可以在 # 号前加一个随机数或者时间戳,但这种方式会改变url:方式二:在组件上加key,强制刷新页面. 方式一

  • 聊聊Vue中provide/inject的应用详解

    众所周知,在组件式开发中,最大的痛点就在于组件之间的通信.在 Vue 中,Vue 提供了各种各样的组件通信方式,从基础的 props/$emit 到用于兄弟组件通信的 EventBus,再到用于全局数据管理的 Vuex. 在这么多的组件通信方式中,provide/inject 显得十分阿卡林(毫无存在感).但是,其实 provide/inject 也有它们的用武之地.今天,我们就来聊聊 Vue 中 provide/inject 的应用. 何为 provide/inject provide/inj

  • Vue中slot的使用详解

    目录 使用 slot 基础用法 具名插槽 作用域插槽 slot 实现 总结 在Vue中,我们使用组件来组织页面和组织代码,类似于搭积木,每一个组件都是一个积木,使用一些相同或者不同组件就能搭建出我们想要的页面. slot(插槽)是组件功能的重要组成部分,插槽必须用于组件才有意义. 它为组件提供了对外的接口,允许从组件外部传递内容,并将这部分内容放置到指定的位置. 使用 slot 当一个组件可能被使用至少两次并且两次使用内容(这里指组件视图的组成)不同时,插槽才有存在的必要.注意: 本文的代码都是

  • vue中methods、mounted等的使用方法解析

    目录 methods.mounted的使用方法 vue生命周期(methods.mounted) 1.什么是生命周期 2.钩子函数 3.Vue生命周期之初始化阶段 methods.mounted的使用方法 created:html加载完成之前,执行.执行顺序:父组件-子组件 mounted:html加载完成后执行.执行顺序:子组件-父组件 methods:事件方法执行. watch:去监听一个值的变化,然后执行相对应的函数. computed:computed是计算属性,也就是依赖其它的属性计算

  • vue中引入路径@的用法及说明

    目录 引入路径@的用法及说明 Vue文件中引用路径的介绍 Vue中使用 vue项目路径使用@的原因 @是webpack设置的路径别名 使用场景 引入路径@的用法及说明 Vue文件中引用路径的介绍 1.路径 ./ ./当前文件同级目录 2.路径 …/ …/当前文件上一级目录 3.@符号 @ 的作用是在你引入模块时,可以使用 @ 代替 /src 目录,避免易错的相对路径. Vue中使用 1. vue.config.js配置文件中使用   chainWebpack(config) {     conf

  • Vue中router-link常用属性使用案例讲解

    目录 Vue中router-link常用属性使用 router-link属性 vue中的router-link属性详解 router-link标签 router-link属性值详解 Vue中router-link常用属性使用 在vue1.0版本的超链接标签还是原来的a标签,链接地址由v-link属性控制而vue2.0版本里超链接标签由a标签被替换成了router-link标签,但最终在页面还是会被渲染成a标签的至于为什么要把a换成router-link原因还是有的,比如我们之前一直惯用的nav导

  • vue 中使用print.js导出pdf操作

    1.print.js // 打印类属性.方法定义 /* eslint-disable */ const Print = function (dom, options) { if (!(this instanceof Print)) return new Print(dom, options); this.options = this.extend({ 'noPrint': '.no-print' }, options); if ((typeof dom) === "string") {

随机推荐