http://localhost:8080 作为示例地址)。# 创建新项目(已有项目可跳过)npm create vue@3 onlyoffice-vue3-democd onlyoffice-vue3-demo# 安装 ONLYOFFICE Vue 组件npm install --save @onlyoffice/document-editor-vue
<template><divstyle="width: 100%; height: 90vh; border: 1px solid #eee;"><DocumentEditorid="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 必须使用:slidedocumentType: '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: {autosave: true, // 自动保存showToolbar: true, // 显示工具栏},},});// 加载失败const onLoadError = (err) => {console.error('PPT 编辑器加载失败:', err);};// 加载完成const onDocumentReady = () => {console.log('PPT 加载完成,可编辑');};// 保存触发const onDocumentSave = (e) => {console.log('PPT 自动保存触发:', e);};</script>
<template><div><h2>ONLYOFFICE PPT 在线编辑</h2><OnlyOfficePptEditor /></div></template><scriptsetup>import OnlyOfficePptEditor from './components/OnlyOfficePptEditor.vue';</script>
documentType | slide | |
fileType | pptx | |
mode | edit | |
url |
pptx、ppsx、odpppt、pps后端保存接口
和 Word、Excel 完全通用,不需要任何修改。
常见问题
- 1,PPT 打不开
确认 documentType: 'slide'确认文件是 .pptx
确认 mode: 'edit'确认 Document Server 正常运行 - 3,页面空白
检查 url地址是否能公网 / 内网访问
夜雨聆风