Skip to content

组件使用

PrintTemplateStudio 是可直接嵌入业务应用的打印模板主组件。

Props

名称类型说明
templateobject | null当前模板文档,支持外部控制与回写。
runtimeDataobject预览和打印使用的业务数据。
repositoryobject | null可替换的模板仓储,不传时使用本地存储。
storageKeystring本地仓储命名空间。
heightstring | number编辑器高度,默认 720

Events

名称说明
update:template模板发生变化时回写。
update:runtimeData运行时数据发生变化时回写。
template-change模板变更通知。
error仓储、解析或打印错误。
ready组件挂载完成。

暴露方法

方法说明
loadTemplateDocument(document)载入模板文档。
getTemplateDocument()获取当前模板。
getPublishReadyTemplatePayload()获取可发布载荷。
setRuntimeData(data)更新运行时数据。
print(data?)打印当前内容,必要时可先注入数据。

常见用法

vue
<script setup>
import { ref } from "vue";

const template = ref();
const runtimeData = ref({});

function handleError(payload) {
  console.error(payload.scope, payload.message);
}
</script>

<template>
  <PrintTemplateStudio
    ref="designer"
    v-model:template="template"
    v-model:runtime-data="runtimeData"
    storage-key="invoice-template"
    :height="780"
    @error="handleError"
  />
</template>

开源协议:MIT