Vue examples

Find Vue examples for loading, saving, custom chrome, and automating an open editor.

Choose an example

TaskSource
Load from a URL and save through the refLoading and saving
Build custom toolbar buttonsVue composables
Arrange editor partsVue composition
Automate the open documentAutomate an open editor

Automate an open editor

Install the editing API. It requires the EigenPal Pro License.

npm install @docx-editor.dev/editor-api

Render 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 through editor.value, and wait for it before you create the runtime.
  • Load explicit properties, such as load('text'), and await context.sync() before you read them.
  • Dispose the runtime in finally.
  • save() on the ref can return null. Your app owns any upload of the saved bytes.

Next steps