vue-print-nb只打印一頁解決方法示例
vue-print-nb打印
經我研究多天,因為我是從接口拿的數據,數據量會很多,但是vue-print-nb這個插件只打印了21條表格數據,又嘗試了print.js的方法,依舊不行,達不到我想要的效果,然后我繼續(xù)研究了vue-print-nb這個打印方法。。。
第一步:vue項目得下個依賴包
命令是
npm install vue-print-nb --save
下載依賴成功后
第二步:全局引入,或者局部引入
//全局引入在main.js文件里 import Print from 'vue-print-nb' Vue.use(Print) //局部引入是在組件里 import Print from 'vue-print-nb'
同時自定義一個指令
directives: {
Print
},
第三步: 使用
給你打印的內容加上一個id,例如打印表格就是
<template>
<v-simple-table id="printTable">
<template v-slot:default>
<thead>
<tr>
<th class="text-left">
Name
</th>
<th class="text-left">
Calories
</th>
</tr>
</thead>
<tbody>
<tr
v-for="item in desserts"
:key="item.name"
>
<td>{{ item.name }}</td>
<td>{{ item.calories }}</td>
</tr>
</tbody>
</template>
</v-simple-table>
</template>打印的按鈕
<v-btn depressed primary v-print="printObj">{{打印}}</v-btn>data()里面定義打印的方法(注:是在data里面,不是methods)
printObj: {
id: 'printTable',
// extraCss: 'https://www.google.com,https://www.google.com'
// extraHead: '<meta http-equiv="Content-Language"content="zh-cn"/>'
},第四步: 最最最最關鍵的一步,也就是解決只能打印一頁的問題,就調整樣式
@media print {
@page {
size: auto;
}
body, html,div{
height: auto!important;
}
}
</style>這個div啊設置成高度自適應,全部數據都能打印出來了,啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊。。。。,困擾我多天的問題終于解決了
以上就是vue-print-nb只打印一頁解決方法示例的詳細內容,更多關于vue-print-nb打印的資料請關注腳本之家其它相關文章!
相關文章
vue+element多選級聯選擇器自定義props使用詳解
這篇文章主要給大家介紹了關于vue+element多選級聯選擇器自定義props使用的相關資料,級聯選擇器展示的結果都是以數組的形式展示,也就是v-model綁定的結果,需要的朋友可以參考下2023-07-07

