# docx-editor-auto-save

> Word editor that saves the document as a docx blob periodically after edits.

**Framework:** vue  **Component:** DocxEditor  **Variant:** auto-save

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/vue/docx-editor-auto-save.json
```

**Install Package(s)**

```bash
npm install @syncfusion/ej2-vue-buttons @syncfusion/ej2-vue-documenteditor @syncfusion/ej2-vue-splitbuttons
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/docx-editor-auto-save/DocxEditor.vue

```vue
<template>
  <div>
    <div class="col-lg-9 control-section">
      <div class="default-section">
        <div ref="de_titlebar" id="documenteditor_titlebar" class="e-de-ctn-title">
          <div
            v-on:keydown="titleBarKeydownEvent"
            v-on:click="titleBarClickEvent"
            class="single-line"
            id="documenteditor_title_contentEditor"
            title="Document Name. Click or tap to rename this document."
            contenteditable="false"
          >
            <label
              v-on:blur="titleBarBlurEvent"
              id="documenteditor_title_name"
              :style="titileStyle"
            >
              {{ documentName }}
            </label>
          </div>
          <ejs-button
            ref="de-print"
            id="de-print"
            :style="iconStyle"
            :iconCss="printIconCss"
            v-on:click="printBtnClick"
            title="Print this document (Ctrl+P)."
          >
            Print
          </ejs-button>
          <ejs-dropdownbutton
            ref="de-export"
            :style="iconStyle"
            :items="exportItems"
            :iconCss="exportIconCss"
            cssClass="e-caret-hide"
            content="Download"
            v-bind:select="onExport"
            :open="openExportDropDown"
            title="Download this document."
          ></ejs-dropdownbutton>
        </div>
        <ejs-documenteditorcontainer
          ref="doceditcontainer"
          :toolbarMode="'Ribbon'"
          :serviceUrl="hostUrl"
          :enableToolbar="true"
          class="editor-container"
        ></ejs-documenteditorcontainer>
      </div>
    </div>
    <div class="col-lg-3 property-section">
      <table id="property" title="Auto save log">
        <tbody>
          <tr>
            <td>
              <div class="eventarea" style="height: 150px; overflow: auto">
                <span class="AutosaveLog" id="AutosaveLog" style="word-break: normal;"></span>
              </div>
            </td>
          </tr>
          <tr>
            <td>
              <div class="evtbtn" style="padding-bottom: 10px">
                <ejs-button v-on:click="clearLog" id="clear">Clear</ejs-button>
              </div>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</template>

<script lang="ts">
import {
  DocumentEditorContainerComponent,
  Toolbar,
  Ribbon
} from '@syncfusion/ej2-vue-documenteditor';
import { DropDownButtonComponent } from '@syncfusion/ej2-vue-splitbuttons';
import { ButtonComponent } from '@syncfusion/ej2-vue-buttons';
import { defaultDocument } from '../datasource/docx-editor-data';

export default {
  name: 'DocxEditor',
  components: {
    'ejs-documenteditorcontainer': DocumentEditorContainerComponent,
    'ejs-dropdownbutton': DropDownButtonComponent,
    'ejs-button': ButtonComponent
  },
  data() {
    return {
      hostUrl: 'https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/',
      documentName: 'Auto Save',
      documentTitle: 'Untitled Document',
      contentChanged: false,
      autoSaveInterval: 0 as unknown as ReturnType<typeof setInterval>,
      iconStyle:
        'float:right;background: transparent;box-shadow:none;border-color: transparent;border-radius: 2px;color:inherit;font-size:12px;text-transform:capitalize;margin-top:4px;height:28px;font-weight:400;font-family:inherit;',
      titileStyle:
        'text-transform:capitalize;font-weight:400;font-family:inherit;text-overflow:ellipsis;white-space:pre;overflow:hidden;user-select:none;cursor:text',
      openIconCss: 'e-de-icon-Open e-de-padding-right',
      printIconCss: 'e-de-icon-Print e-de-padding-right',
      exportIconCss: 'e-de-icon-Download e-de-padding-right',
      exportItems: [
        { text: 'Syncfusion Document Text (*.sfdt)', id: 'sfdt' },
        { text: 'Word Document (*.docx)', id: 'word' },
        { text: 'Word Template (*.dotx)', id: 'dotx' },
        { text: 'Plain Text (*.txt)', id: 'txt' }
      ]
    };
  },
  provide: {
    DocumentEditorContainer: [Toolbar, Ribbon]
  },
  methods: {
    onExport: function (args: any) {
      switch (args.item.id) {
        case 'word':
          this.save('Docx');
          break;
        case 'sfdt':
          this.save('Sfdt');
          break;
        case 'txt':
          this.save('Txt');
          break;
        case 'dotx':
          this.save('Dotx');
          break;
      }
    },
    openExportDropDown: function () {
      document
        .getElementById('word')
        ?.setAttribute('title', 'Download a copy of this document to your computer as a DOCX file.');
      document
        .getElementById('sfdt')
        ?.setAttribute('title', 'Download a copy of this document to your computer as an SFDT file.');
      document
        .getElementById('txt')
        ?.setAttribute('title', 'Download a copy of this document to your computer as a TXT file.');
      document
        .getElementById('dotx')
        ?.setAttribute('title', 'Download a copy of this document to your computer as a DOTX file.');
    },
    save: function (format: string) {
      const editor = (this.$refs.doceditcontainer as any).ej2Instances.documentEditor;
      editor.save(
        editor.documentName === '' ? 'sample' : editor.documentName,
        format
      );
    },
    clearLog: function () {
      const log = document.getElementById('AutosaveLog');
      if (log) {
        log.innerHTML = '';
      }
    },
    printBtnClick: function () {
      const editor = (this.$refs.doceditcontainer as any).ej2Instances.documentEditor;
      editor.print();
    },
    titleBarKeydownEvent: function (e: KeyboardEvent) {
      if (e.keyCode === 13) {
        e.preventDefault();
        const contentEditor = document.getElementById('documenteditor_title_contentEditor');
        if (contentEditor) {
          contentEditor.setAttribute('contenteditable', 'false');
          if (contentEditor.textContent === '') {
            contentEditor.textContent = 'Document1';
          }
        }
      }
    },
    titleBarBlurEvent: function () {
      const contentEditor = document.getElementById('documenteditor_title_contentEditor');
      if (contentEditor && contentEditor.textContent === '') {
        contentEditor.textContent = 'Document1';
      }
      if (contentEditor) {
        contentEditor.setAttribute('contenteditable', 'false');
      }
      const titleName = document.getElementById('documenteditor_title_name');
      if (titleName && contentEditor) {
        (this.$refs.doceditcontainer as any).ej2Instances.documentEditor.documentName =
          contentEditor.textContent;
      }
    },
    titleBarClickEvent: function () {
      this.updateDocumentEditorTitle();
    },
    updateDocumentEditorTitle: function () {
      const contentEditor = document.getElementById('documenteditor_title_contentEditor');
      if (contentEditor) {
        contentEditor.setAttribute('contenteditable', 'true');
        contentEditor.focus();
        const sel = window.getSelection();
        if (sel) {
          sel.selectAllChildren(contentEditor);
        }
      }
    },
    documentChangedEvent: function () {
      const editor = (this.$refs.doceditcontainer as any).ej2Instances.documentEditor;
      this.documentTitle = editor.documentName === '' ? 'Untitled Document' : editor.documentName;
      const titleName = document.getElementById('documenteditor_title_name');
      if (titleName) {
        titleName.textContent = editor.documentName;
      }
      setTimeout(() => {
        editor.scrollToPage(1);
      }, 10);
    }
  },
  mounted() {
    this.$nextTick(() => {
      const container = (this.$refs.doceditcontainer as any).ej2Instances;
      const editor = container.documentEditor;
      editor.open(JSON.stringify(defaultDocument));
      editor.documentName = 'Auto Save';
      container.documentEditorSettings.showRuler = true;
      container.documentChange = () => {
        this.documentChangedEvent();
      };

      this.autoSaveInterval = setInterval(() => {
        if (this.contentChanged) {
          editor.saveAsBlob('Docx').then(() => {
            const span = document.createElement('span');
            const date = new Date();
            const time = date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
            span.innerHTML = 'Auto saved at <b>' + time + '</b><hr>';
            const log = document.getElementById('AutosaveLog');
            if (log) {
              log.insertBefore(span, log.firstChild);
            }
          });
          this.contentChanged = false;
        }
      }, 15000);

      container.contentChange = () => {
        this.contentChanged = true;
      };
    });
  },
  beforeUnmount() {
    // Cleanup interval on component destruction
    clearInterval(this.autoSaveInterval);
  }
};
</script>

<style scoped>
div:first-child {
  display: flex;
  width: 100%;
  height: 100%;
  gap: 0;
}

.control-section {
  padding: 20px;
  flex: 1;
}

.col-lg-9 {
  flex: 0.75;
  padding-right: 20px;
}

.col-lg-3 {
  flex: 0.25;
  padding-left: 20px;
  border-left: 1px solid #ddd;
}

div > div:first-child {
  display: flex;
  gap: 20px;
}

.default-section {
  border: 1px solid #ddd;
  border-radius: 4px;
  background-color: #f9f9f9;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
}

.editor-container {
  flex: 1;
  width: 100%;
}

.e-de-ctn-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  background-color: #f5f5f5;
  border-bottom: 1px solid #ddd;
}

.single-line {
  flex: 1;
  min-width: 200px;
}

#documenteditor_title_name {
  cursor: text;
  padding: 5px;
  border-radius: 4px;
  transition: background-color 0.3s;
}

#documenteditor_title_name:hover {
  background-color: #e8f0fe;
}

.property-section {
  padding: 20px;
  background-color: #f9f9f9;
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  min-height: 700px;
}

.content-wrapper {
  padding: 10px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

td {
  padding: 10px;
}

.eventarea {
  border: 1px solid #ddd;
  padding: 10px;
  background-color: white;
  border-radius: 4px;
}

.evtbtn {
  text-align: center;
}
</style>

```
