欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue-print如何實(shí)現(xiàn)打印功能

 更新時(shí)間:2025年04月24日 10:52:22   作者:小泡泡c  
這篇文章主要介紹了vue-print如何實(shí)現(xiàn)打印功能問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

一、安裝

1. Vue2

npm install vue-print-nb --save
import Print from 'vue-print-nb'
// Global instruction 
Vue.use(Print);

//or

// Local instruction
import print from 'vue-print-nb'

directives: {
    print   
}

2. Vue3

npm install vue3-print-nb --save
// Global instruction 
import { createApp } from 'vue'
import App from './App.vue'
import print from 'vue3-print-nb'
const app = createApp(App)
app.use(print)
app.mount('#app')

//or

// Local instruction
import print from 'vue3-print-nb'

directives: {
    print   
}

二、基本使用

1. 直接打印頁(yè)面HTML

1)方法

  • ① 給要打印的部分設(shè)置一個(gè) id
  • ② 在打印按鈕中添加 v-print="'#id名'"

2)代碼(以表格為例)

<template>
  <div>
    <a-button v-print="'#printMe'">打印</a-button>
    <a-table :columns="columns" :data-source="data" bordered id="printMe">
  	</a-table>
  </div>
</template>
<script>
const columns = [
  {
    title: 'Name',
    dataIndex: 'name',
  },
  {
    title: 'Cash Assets',
    className: 'column-money',
    dataIndex: 'money',
  },
  {
    title: 'Address',
    dataIndex: 'address',
  },
];

const data = [
  {
    key: '1',
    name: 'John Brown',
    money: '¥300,000.00',
    address: 'New York No. 1 Lake Park',
  },
  {
    key: '2',
    name: 'Jim Green',
    money: '¥1,256,000.00',
    address: 'London No. 1 Lake Park',
  },
  {
    key: '3',
    name: 'Joe Black',
    money: '¥120,000.00',
    address: 'Sidney No. 1 Lake Park',
  },
];

export default {
  data() {
    return {
      data,
      columns,
    };
  },
};
</script>

2. 個(gè)性化設(shè)置

1)方法

打印按鈕的 v-print 綁定一個(gè)對(duì)象

2)代碼

<template>
  <div class="box">
    <a-table :columns="columns" :data-source="data" bordered id="printMe"></a-table>
    <a-button v-print="printContent" class="btn no-print">打印</a-button>
  </div>
</template>
<script>
const columns = [
  {
    title: 'Name',
    dataIndex: 'name',
  },
  {
    title: 'Cash Assets',
    className: 'column-money',
    dataIndex: 'money',
  },
  {
    title: 'Address',
    dataIndex: 'address',
  },
];

const data = [
  {
    key: '1',
    name: 'John Brown',
    money: '¥300,000.00',
    address: 'New York No. 1 Lake Park',
  },
  {
    key: '2',
    name: 'Jim Green',
    money: '¥1,256,000.00',
    address: 'London No. 1 Lake Park',
  },
  {
    key: '3',
    name: 'Joe Black',
    money: '¥120,000.00',
    address: 'Sidney No. 1 Lake Park',
  },
];

export default {
  data() {
    return {
      data,
      columns,
      tableHead: '測(cè)試表格',
      printContent: {
        id: "printMe", // 打印的區(qū)域
        preview: false, // 預(yù)覽工具是否啟用
        previewTitle: '這是預(yù)覽標(biāo)題', // 預(yù)覽頁(yè)面的標(biāo)題
        popTitle: '', // 打印頁(yè)面的頁(yè)眉
        extraCss: "https://cdn.bootcdn.net/ajax/libs/animate.css/4.1.1/animate.compat.css, https://cdn.bootcdn.net/ajax/libs/hover.css/2.3.1/css/hover-min.css",
        extraHead: '<meta http-equiv="Content-Language"content="zh-cn"/>',
        previewBeforeOpenCallback() {
          console.log('正在加載預(yù)覽窗口')
        },
        previewOpenCallback() {
          console.log('已經(jīng)加載完預(yù)覽窗口')
        },
        beforeOpenCallback(vue) {
          vue.printLoading = true
          console.log('打開(kāi)之前')
        },
        openCallback(vue) {
          vue.printLoading = false
          console.log('執(zhí)行了打印')
        },
        closeCallback() {
          console.log('關(guān)閉了打印工具')
        },
        clickMounted(vue){
          console.log('點(diǎn)擊了打印按鈕');
          vue.printContent.popTitle = vue.tableHead // 動(dòng)態(tài)設(shè)置頁(yè)眉
        }
      }
    }
  }
};
</script>

3)效果展示

① 預(yù)覽工具

3. 打印URL

1)方法

  • ① 給 打印按鈕的 v-print 綁定一個(gè)對(duì)象
  • ② 對(duì)象添加 url 屬性

2)代碼

<template>
  <div class="box">
    <a-table :columns="columns" :data-source="data" bordered></a-table>
    <a-button v-print="printContent" class="btn no-print" >打印</a-button>
  </div>
</template>
<script>
const columns = [
  {
    title: 'Name',
    dataIndex: 'name',
  },
  {
    title: 'Cash Assets',
    className: 'column-money',
    dataIndex: 'money',
  },
  {
    title: 'Address',
    dataIndex: 'address',
  },
];

const data = [
  {
    key: '1',
    name: 'John Brown',
    money: '¥300,000.00',
    address: 'New York No. 1 Lake Park',
  },
  {
    key: '2',
    name: 'Jim Green',
    money: '¥1,256,000.00',
    address: 'London No. 1 Lake Park',
  },
  {
    key: '3',
    name: 'Joe Black',
    money: '¥120,000.00',
    address: 'Sidney No. 1 Lake Park',
  },
];

export default {
  data() {
    return {
      data,
      columns,
      tableHead: '測(cè)試表格',
      printContent: {
        url: 'http://localhost:8081/', // 打印的url
        preview: false, // 預(yù)覽工具是否啟用
        previewTitle: '這是預(yù)覽標(biāo)題',
        popTitle: '', // 打印頁(yè)面的頁(yè)眉
        extraCss: "https://cdn.bootcdn.net/ajax/libs/animate.css/4.1.1/animate.compat.css, https://cdn.bootcdn.net/ajax/libs/hover.css/2.3.1/css/hover-min.css",
        extraHead: '<meta http-equiv="Content-Language"content="zh-cn"/>',
      }
    }
  },
};
</script>

三、API

ParameExplainTypeOptionalValueDefaultValue
idRange print ID, required valueString
standardDocument type (Print local range only)Stringhtml5/loose/stricthtml5
extraHeadAdd DOM nodes in the node, and separate multiple nodes with , (Print local range only)String
extraCssNew CSS style sheet , and separate multiple nodes with ,(Print local range only)String
popTitleContent of label (Print local range only)String
openCallbackCall the successful callback function of the printing toolFunctionReturns the instance of Vue called at that time
closeCallbackClose the callback function of printing tool successFunctionReturns the instance of Vue called at that time
beforeOpenCallbackCallback function before calling printing toolFunctionReturns the instance of Vue called at that time
urlPrint the specified URL. (It is not allowed to set the ID at the same time)String
asyncUrlReturn URL through ‘resolve()’ and VueFunction
previewPreview toolBooleanfalse
previewTitlePreview tool TitleString‘打印預(yù)覽’
previewPrintBtnLabelThe name of the preview tool buttonString‘打印’
zIndexCSS of preview tool: z-indexString,Number20002
previewBeforeOpenCallbackCallback function before starting preview toolFunctionReturns the instance of Vue
previewOpenCallbackCallback function after fully opening preview toolFunctionReturns the instance of Vue
clickMountedClick the callback function of the print buttonFunctionReturns the instance of Vue

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • 從零開(kāi)始在vue-cli4配置自適應(yīng)vw布局的實(shí)現(xiàn)

    從零開(kāi)始在vue-cli4配置自適應(yīng)vw布局的實(shí)現(xiàn)

    這篇文章主要介紹了從零開(kāi)始在vue-cli4配置自適應(yīng)vw布局,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-06-06
  • vue3?hook自動(dòng)導(dǎo)入原理及使用

    vue3?hook自動(dòng)導(dǎo)入原理及使用

    最近學(xué)習(xí)了hooks,特地寫一篇文章加深一下印象,下面這篇文章主要給大家介紹了關(guān)于vue3?hook自動(dòng)導(dǎo)入原理及使用的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-10-10
  • vue 使用localstorage實(shí)現(xiàn)面包屑的操作

    vue 使用localstorage實(shí)現(xiàn)面包屑的操作

    這篇文章主要介紹了vue 使用localstorage實(shí)現(xiàn)面包屑的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-11-11
  • 在Vue項(xiàng)目中優(yōu)化字體文件的加載和緩存的常用方法

    在Vue項(xiàng)目中優(yōu)化字體文件的加載和緩存的常用方法

    在現(xiàn)代 Web 開(kāi)發(fā)中,字體文件通常是頁(yè)面加載時(shí)間的重要因素之一,特別是在字體文件較大或網(wǎng)絡(luò)環(huán)境不佳的情況下,用戶體驗(yàn)可能會(huì)受到影響,本文將詳細(xì)探討如何在 Vue.js 項(xiàng)目中優(yōu)化字體文件的加載和緩存,以提高頁(yè)面性能,需要的朋友可以參考下
    2024-09-09
  • vue中v-bind和v-model的區(qū)別及說(shuō)明

    vue中v-bind和v-model的區(qū)別及說(shuō)明

    這篇文章主要介紹了vue中v-bind和v-model的區(qū)別及說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-08-08
  • vue-cli 介紹與安裝

    vue-cli 介紹與安裝

    這篇文章主要給大家介紹的是vue-cli 介紹與安裝,vue-cli是和vue進(jìn)行深度組合的工具,可以快速幫我們創(chuàng)建vue項(xiàng)目,并且把一些腳手架相關(guān)的代碼給我們創(chuàng)建好。真正使用vue開(kāi)發(fā)項(xiàng)目,都是用vue-cli來(lái)創(chuàng)建項(xiàng)目的,下面文章詳細(xì)內(nèi)容,需要的朋友可以參考一下
    2021-10-10
  • VUE3項(xiàng)目VITE打包優(yōu)化的實(shí)現(xiàn)

    VUE3項(xiàng)目VITE打包優(yōu)化的實(shí)現(xiàn)

    本文主要介紹了VUE3項(xiàng)目VITE打包優(yōu)化的實(shí)現(xiàn),包括使用視圖分析工具、路由懶加載、第三方庫(kù)CDN引入、gzip壓縮、按需引入第三方庫(kù)、TreeShaking、剔除console和debugger、分包策略和圖片壓縮等,具有一定的參考價(jià)值,感興趣的可以了解一下
    2025-03-03
  • 淺談Vue3 父子傳值

    淺談Vue3 父子傳值

    這篇文章主要介紹了基于Vue中的父子傳值問(wèn)題解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2021-10-10
  • 使用vue中的混入mixin優(yōu)化表單驗(yàn)證插件問(wèn)題

    使用vue中的混入mixin優(yōu)化表單驗(yàn)證插件問(wèn)題

    這篇文章主要介紹了使用vue中的混入mixin優(yōu)化表單驗(yàn)證插件,本文是小編給大家總結(jié)的一些表單插件的問(wèn)題,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-07-07
  • vue使用video插件vue-video-player詳解

    vue使用video插件vue-video-player詳解

    這篇文章主要為大家詳細(xì)介紹了vue使用video插件vue-video-player,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-10-10

最新評(píng)論