最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

一、安裝

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. 直接打印頁面HTML

1)方法

  • ① 給要打印的部分設置一個 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. 個性化設置

1)方法

打印按鈕的 v-print 綁定一個對象

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: '測試表格',
      printContent: {
        id: "printMe", // 打印的區(qū)域
        preview: false, // 預覽工具是否啟用
        previewTitle: '這是預覽標題', // 預覽頁面的標題
        popTitle: '', // 打印頁面的頁眉
        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('正在加載預覽窗口')
        },
        previewOpenCallback() {
          console.log('已經(jīng)加載完預覽窗口')
        },
        beforeOpenCallback(vue) {
          vue.printLoading = true
          console.log('打開之前')
        },
        openCallback(vue) {
          vue.printLoading = false
          console.log('執(zhí)行了打印')
        },
        closeCallback() {
          console.log('關閉了打印工具')
        },
        clickMounted(vue){
          console.log('點擊了打印按鈕');
          vue.printContent.popTitle = vue.tableHead // 動態(tài)設置頁眉
        }
      }
    }
  }
};
</script>

3)效果展示

① 預覽工具

3. 打印URL

1)方法

  • ① 給 打印按鈕的 v-print 綁定一個對象
  • ② 對象添加 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: '測試表格',
      printContent: {
        url: 'http://localhost:8081/', // 打印的url
        preview: false, // 預覽工具是否啟用
        previewTitle: '這是預覽標題',
        popTitle: '', // 打印頁面的頁眉
        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‘打印預覽’
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

總結

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

相關文章

  • vue vant Area組件使用詳解

    vue vant Area組件使用詳解

    這篇文章主要介紹了vue vant Area組件使用詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-12-12
  • vue移動端設置全屏背景的項目實踐

    vue移動端設置全屏背景的項目實踐

    本vue移動端項目設置全屏背景,關鍵是要找對文件,然后添加background屬性即可,文中通過示例代碼介紹的非常詳細,需要的朋友們下面隨著小編來一起學習學習吧
    2023-08-08
  • Vue如何通過瀏覽器控制臺查看全局data值

    Vue如何通過瀏覽器控制臺查看全局data值

    在寫vue項目時想到一個問題,項目里面的文件都是一個個的組件,如何在控制臺中修改,查看組件data里的值呢,下面這篇文章主要給大家介紹了關于Vue如何通過瀏覽器控制臺查看全局data值的相關資料,需要的朋友可以參考下
    2023-04-04
  • Vue3中引入scss文件的方法步驟

    Vue3中引入scss文件的方法步驟

    這篇文章主要給大家介紹了關于Vue3中引入scss文件的方法步驟,在實際項目中,各種樣式往往有很多重復的情況,為了能夠使樣式的后續(xù)開發(fā)和維護更加愜意,將這些共同的代碼進行命名然后調(diào)用這些變量是一個很好的選擇,需要的朋友可以參考下
    2023-08-08
  • Vue elementui字體圖標顯示問題解決方案

    Vue elementui字體圖標顯示問題解決方案

    這篇文章主要介紹了Vue elementui字體圖標顯示問題解決方案,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-08-08
  • vue2.0+webpack環(huán)境的構造過程

    vue2.0+webpack環(huán)境的構造過程

    本文分步驟給大家介紹了vue2.0+webpack環(huán)境的構造過程的相關資料,非常不錯具有參考借鑒價值,需要的朋友可以參考下
    2016-11-11
  • vue路由組件按需加載的幾種方法小結

    vue路由組件按需加載的幾種方法小結

    這篇文章主要介紹了vue路由組件按需加載的幾種方法小結,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-07-07
  • 實例詳解vue中的代理proxy

    實例詳解vue中的代理proxy

    這篇文章主要介紹了vue中的代理proxy,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-02-02
  • 一文輕松理解Vuex

    一文輕松理解Vuex

    這篇文章主要介紹了Vuex及其使用方法,感興趣的同學,可以參考下
    2021-04-04
  • Vue父子組件數(shù)據(jù)雙向綁定(父傳子、子傳父)及ref、$refs、is、:is的使用與區(qū)別

    Vue父子組件數(shù)據(jù)雙向綁定(父傳子、子傳父)及ref、$refs、is、:is的使用與區(qū)別

    這篇文章主要介紹了Vue父子組件數(shù)據(jù)雙向綁定(父傳子、子傳父)及ref、$refs、is、:is的使用與區(qū)別,需要的朋友可以參考下
    2022-12-12

最新評論

宿州市| 南安市| 桑日县| 宜城市| 繁峙县| 宣化县| 鄄城县| 尚志市| 万安县| 遂昌县| 寿宁县| 呼伦贝尔市| 伊金霍洛旗| 灌云县| 平山县| 博野县| 乌兰县| 揭西县| 怀远县| 洞口县| 石景山区| 东丰县| 靖边县| 东兴市| 平乡县| 永昌县| 报价| 沾化县| 肥城市| 湘乡市| 庆城县| 宁海县| 蚌埠市| 色达县| 青铜峡市| 瑞昌市| 黄陵县| 满洲里市| 天全县| 贵溪市| 特克斯县|