vue-print-nb打印组件
这是一个简单方便的打印组件。
用法
HTML:
<div id="printMe">打印我</div>
<button v-print="'#printMe'">打印</button>
<button v-print="printObj">打印</button>
javascript:
export default {
data() {
return {
printObj: {
id:''
ignoreClass:'',
beforeOpenCallback (vue) {
console.log('打开之前')
},
openCallback (vue) {
console.log('执行了打印')
},
closeCallback (vue) {
console.log('关闭了打印工具')
}
}
};
}
}
v-print API
| id | 打印元素的ID | String | — | — |
| standard | 文档类型(仅打印本地范围) | String | html5/loose/strict | html5 |
| extraHead | <head></head>在节点中添加DOM节点,并使用 ,(仅打印本地范围) | String | — | — |
| extraCss | <link> 新的CSS样式表,并使用 ,(仅打印本地范围) | String | — | - |
| popTitle | <title></title> 标签内容 (仅打印本地范围) | String | — | - |
| openCallback | 调用打印工具的成功回调函数 | Function | Returns the instance of Vue called at that time | - |
| closeCallback | 关闭打印工具成功的回调函数 | Function | Returns the instance of Vue called at that time | - |
| beforeOpenCallback | 调用打印工具前的回调函数 | Function | Returns the instance of Vue called at that time | - |
| url | 打印指定的URL。(不允许同时设置ID) | string | - | - |
| asyncUrl | Return URL through 'resolve()' and Vue | Function | - | - |
| preview | 预览工具 | Boolean | - | false |
| previewTitle | 预览工具标题 | String | - | '打印预览' |
| previewPrintBtnLabel | 预览工具按钮的名称 | String | - | '打印' |
| zIndex | 预览工具的CSS:索引 | String,Number | - | 20002 |
| previewBeforeOpenCallback | 启动预览工具前的回调函数 | Function | Returns the instance of Vue | - |
| previewOpenCallback | 完全打开预览工具后的回调函数 | Function | Returns the instance of Vue | - |
| clickMounted | 单击打印按钮的回调函数 | Function | Returns the instance of Vue | - |
源码存放在components\vue-print-nb\src\packages下,如果想修改可以参考以下文章:
博客园