Vue examples
Find Vue examples for loading, saving, custom chrome, and automating an open editor.
Choose an example
| Task | Source |
|---|---|
| Load from a URL and save through the ref | Loading and saving |
| Build custom toolbar buttons | Vue composables |
| Arrange editor parts | Vue composition |
| Automate the open document | Automate an open editor |
Automate an open editor
Install the editing API. It requires the EigenPal Pro License.
npm install @docx-editor.dev/editor-apiRender this component inside DocxEditor.Root. It reads the first paragraph and shows its text:
<script setup lang="ts">
import { ref } from 'vue';
import { useDocxEditor } from '@docx-editor.dev/vue';
import { DocxEditor as AutomationEditor } from '@docx-editor.dev/editor-api/browser';
const editor = useDocxEditor();
const text = ref('');
async function readFirstParagraph() {
if (!editor.value) return;
const runtime = AutomationEditor.createBrowser(editor.value);
try {
await runtime.run(async (context) => {
const first = context.document.body.paragraphs.getFirst();
first.load('text');
await context.sync();
text.value = first.text;
});
} finally {
runtime.dispose();
}
}
</script>
<template>
<button :disabled="!editor" @click="readFirstParagraph">Read first paragraph</button>
<output>{{ text }}</output>
</template>Run the Vue example
The examples/vue app shows composed chrome, menu overrides, rulers, and navigation. Run it from the repository root with bun run dev:vue.
Limits
- Render automation components inside
DocxEditor.Root. Read the editor througheditor.value, and wait for it before you create the runtime. - Load explicit properties, such as
load('text'), and awaitcontext.sync()before you read them. - Dispose the runtime in
finally. save()on the ref can returnnull. Your app owns any upload of the saved bytes.
Next steps
- Vue props: Configure
<DocxEditor>and its ref. - Editing API: Use the Office.js-shaped object model.
- Toolbar guide: Find command slot IDs.