Skip to content

组件接口

组件 PrintTemplateStudio

Props

名称类型默认值说明
templateobject | nullnull初始模板文档。
runtimeDataobject{}预览和打印数据。
repositoryobject | nullnull外部模板仓储。
storageKeystringdefault本地仓储命名空间。
heightstring | number720编辑器高度。
printPolicyobject{ allowIncomplete: false }严格预检策略;仅在允许不完整输出时传入 { allowIncomplete: true }

Emits

事件负载
update:template模板文档。
update:runtimeData运行时数据。
template-change模板文档。
error{ scope, error, message }
ready编辑器实例。

Expose

方法说明
loadTemplateDocument(document)加载模板。
getTemplateDocument()获取当前模板。
getPublishReadyTemplatePayload()获取发布载荷。
setRuntimeData(data)设置运行时数据。
print(data?)执行打印。
whenReady()返回编辑器挂载完成后的 Promise;宿主需要在挂载前调用实例方法时使用。

仓储接口

createLocalTemplateRepository() 适合默认场景,createRestTemplateRepository() 适合接入后端服务。

js
import { createRestTemplateRepository } from "@squirtles331/vue3-plugin-print";

const repository = createRestTemplateRepository({
  baseUrl: "https://api.example.com/print",
  getHeaders: () => ({ Authorization: `Bearer ${token}` }),
});

后端建议暴露以下接口:

  • GET /templates
  • GET /templates/:id
  • PUT /templates/:id
  • DELETE /templates/:id

开源协议:MIT