Appearance
print 打印组件
TIP
不要用 flex 布局!不要用 flex 布局!不要用 flex 布局!
基础使用
vue
<script setup lang="ts">
// 是否显示打印
const isPrinter = ref(false)
// 打印组件实例
const fsPrinterRef = ref()
/* 开始打印 */
const onPrint = () => {
//可以使用v-model 也可以使用fsPrinterRef.value?print()方法
isPrinter.value = true
}
</script>
<template>
<fs-printer v-model="isPrinter" ref="fsPrinterRef">
<!-- 要打印的内容 -->
<div style="overflow: auto">
<el-table :data="tableData">
<el-table-column prop="date" label="Date" width="180" />
<el-table-column prop="name" label="Name" width="180">
<template #default="{ row }">
<el-tag type="success">{{ row.name }}</el-tag>
</template>
</el-table-column>
<el-table-column prop="address" label="Address" width="300" />
</el-table>
<div style="margin: 12px 0">更多表单组件演示:</div>
<div>
<el-radio-group v-model="status">
<el-radio value="1">Option 1</el-radio>
<el-radio value="2">Option 2</el-radio>
</el-radio-group>
</div>
<div>
<el-checkbox-group v-model="status2">
<el-checkbox value="1">Option 1</el-checkbox>
<el-checkbox value="2">Option 2</el-checkbox>
</el-checkbox-group>
</div>
</div>
<fs-printer>
</template>
打印 pdf
vue
<script setup lang="ts">
// 引入打印pdf方法
import { printPdf } from '@/components/FsPrinter/util'
const onPrintPdf = () => {
const loading = ElLoading.service({ text: '加载中' })
printPdf({
url: '/test.pdf',
done: () => {
loading.close()
},
})
}
</script>
属性
参数 | 说明 | 类型 | 默认值 | 可选值 |
---|---|---|---|---|
modelValue | 是否显示打印 | Boolean | false | true |
headerStyle | 页眉样式 | Object | ||
bodyStyle | 内容样式 | Object | ||
footerStyle | 页脚样式 | Object | ||
title | 标题 | String | ||
direction | 纸张方向 | String | landscape(横向) portrait(纵向) | |
orientation | 纸张旋转 | String | upright | rotate-left(向左旋转) rotate-right(向右旋转) |
target | 打印位置 | String | _iframe | _self |
static | 是否在页面中显示 | Boolean | false | true |
事件
名称 | 说明 | 返回值 |
---|---|---|
done | 打印结束事件 |
插槽
名称 | 说明 | 参数 |
---|---|---|
default | 默认插槽 | |
header | 页眉插槽 | |
footer | 页脚插槽 |