乐于分享
好东西不私藏

@onlyoffice/document-editor-vue针对PPT文件的预览或编辑

@onlyoffice/document-editor-vue针对PPT文件的预览或编辑
前提:你已有 ONLYOFFICE Document Server(本地 / 内网 / 云服务器均可,本文用 http://localhost:8080 作为示例地址)。
安装依赖
# 创建新项目(已有项目可跳过)npm create vue@3 onlyoffice-vue3-democd onlyoffice-vue3-demo# 安装 ONLYOFFICE Vue 组件npm install --save @onlyoffice/document-editor-vue
OnlyOfficePptEditor.vue
<template>  <divstyle="width: 100%; height: 90vh; border: 1px solid #eee;">    <DocumentEditor      id="pptEditor"      :document-server-url="docServerUrl"      :config="editorConfig"      :on-load-component-error="onLoadError"      :events_onDocumentReady="onDocumentReady"      :events_onDocumentSave="onDocumentSave"    />  </div></template><scriptsetup>import { ref, reactive } from 'vue';import { DocumentEditor } from '@onlyoffice/document-editor-vue';// 你的 ONLYOFFICE Document Server 地址const docServerUrl = ref('http://localhost:8080');// PPT 唯一 KEY(必须每次不同,避免缓存)const pptKey = ref('ppt_' + Date.now());// PPT 编辑器核心配置const editorConfig = reactive({  width'100%',  height'100%',  // ✅ PPT 必须使用:slide  documentType'slide',  // 文档信息  document: {    fileType'pptx'// PPT 格式    key: pptKey.value,    title'演示文稿.pptx',    // ✅ 你的 PPT 文件下载地址(Document Server 可访问)    url'http://localhost:8080/static/demo.pptx',  },  // 编辑器配置  editorConfig: {    mode'edit'// edit 编辑 / view 只读    lang'zh-CN',    user: {      id'user_ppt',      name'演示文稿操作员',    },    // 保存回调(和 Word/Excel 通用)    callbackUrl'http://localhost:3000/api/onlyoffice/callback',    // PPT 专用配置(可选)    customization: {      autosavetrue// 自动保存      showToolbartrue// 显示工具栏    },  },});// 加载失败const onLoadError = (err) => {  console.error('PPT 编辑器加载失败:', err);};// 加载完成const onDocumentReady = () => {  console.log('PPT 加载完成,可编辑');};// 保存触发const onDocumentSave = (e) => {  console.log('PPT 自动保存触发:', e);};</script>
在 App.vue 中使用
<template>  <div>    <h2>ONLYOFFICE PPT 在线编辑</h2>    <OnlyOfficePptEditor />  </div></template><scriptsetup>import OnlyOfficePptEditor from './components/OnlyOfficePptEditor.vue';</script>
PPT 关键配置(和 Word/Excel 区别)
配置项
必须值
说明
documentTypeslide
PPT / 幻灯片专属类型
fileTypepptx
标准可编辑 PPT 格式
modeedit
开启编辑功能
url
.pptx 文件地址
必须能被 Document Server 直接下载
支持的 PPT 格式
✅ 可编辑:pptxppsxodp
✅ 可预览:pptpps

后端保存接口

和 Word、Excel 完全通用,不需要任何修改

常见问题

  1. 1,PPT 打不开
    • 确认 documentType: 'slide'
    • 确认文件是 .pptx
2,无法编辑
    • 确认 mode: 'edit'
    • 确认 Document Server 正常运行
  1. 3,页面空白
    • 检查 url 地址是否能公网 / 内网访问