# docx-editor-comments

> Word editor demonstrates threaded comments and at-mention support in the document.

**Framework:** vue  **Component:** DocxEditor  **Variant:** comments

## 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-comments.json
```

**Install Package(s)**

```bash
npm install @syncfusion/ej2-vue-buttons @syncfusion/ej2-vue-documenteditor @syncfusion/ej2-vue-splitbuttons @syncfusion/ej2-popups
```

**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-comments/DocxEditor.vue

```vue
<template>
  <div>
    <div class="control-section">
      <div class="flex-container">
        <label class="switchLabel" for="checked">Ribbon UI</label>
        <div class="e-message render-mode-info">
          <span
            class="e-msg-icon render-mode-info-icon"
            title="Turn OFF to switch from Ribbon to toolbar UI"
          ></span>
        </div>
        <ejs-switch
          cssClass="buttonSwitch"
          id="toolbarSwitch"
          :change="change"
          :checked="true"
        ></ejs-switch>
      </div>
      <div class="sample-container">
        <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"
            :documentEditorSettings="settings"
            :enableToolbar="true"
            height="600px"
            currentUser="Nancy Davolio"
            userColor="#b70f34"
            :commentDelete="commentDelete"
          ></ejs-documenteditorcontainer>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import {
  DocumentEditorContainerComponent,
  Toolbar,
  Ribbon
} from '@syncfusion/ej2-vue-documenteditor';
import { DropDownButtonComponent } from '@syncfusion/ej2-vue-splitbuttons';
import { DialogUtility } from '@syncfusion/ej2-popups';
import { ButtonComponent, SwitchComponent } from '@syncfusion/ej2-vue-buttons';
import { mentionData, comments } from '../datasource/docx-editor-data';

export default {
  name: 'DocxEditor',
  components: {
    'ejs-documenteditorcontainer': DocumentEditorContainerComponent,
    'ejs-dropdownbutton': DropDownButtonComponent,
    'ejs-button': ButtonComponent,
    'ejs-switch': SwitchComponent
  },
  data() {
    return {
      hostUrl: 'https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/',
      settings: {
        showRuler: true,
        mentionSettings: {
          dataSource: mentionData,
          fields: { text: 'Name' }
        }
      },
      documentName: 'Comments',
      documentTitle: 'Untitled Document',
      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
      );
    },
    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();
    },
    showButtons: function (show: boolean) {
      const displayStyle = show ? 'block' : 'none';
      if (this.$refs['de-print']) {
        (this.$refs['de-print'] as any).$el.style.display = displayStyle;
      }
      if (this.$refs['de-export']) {
        (this.$refs['de-export'] as any).$el.style.display = displayStyle;
      }
    },
    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);
        }
      }
    },
    commentDelete: function (args: any) {
      const editor = (this.$refs.doceditcontainer as any).ej2Instances.documentEditor;
      if (args.author !== editor.currentUser) {
        args.cancel = true;
        DialogUtility.alert({
          title: 'Information',
          content: 'Delete restriction enabled. Only the author of the comment can delete it.',
          showCloseIcon: true,
          closeOnEscape: true
        });
      }
    },
    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);
    },
    change: function (args: any) {
      const container = (this.$refs.doceditcontainer as any).ej2Instances;
      if (args.checked) {
        container.toolbarMode = 'Ribbon';
      } else {
        container.toolbarMode = 'Toolbar';
      }
      this.showButtons(container.toolbarMode != 'Ribbon');
    }
  },
  mounted() {
    this.$nextTick(() => {
      const container = (this.$refs.doceditcontainer as any).ej2Instances;
      const editor = container.documentEditor;
      container.showPropertiesPane = false;
      editor.open(JSON.stringify(comments));
      editor.documentName = 'Comments';
      container.documentEditor.showComments = true;
      container.documentChange = () => {
        this.documentChangedEvent();
      };
      this.showButtons(container.toolbarMode != 'Ribbon');
    });
  }
};
</script>

<style scoped>
.control-section {
  padding: 20px;
}

.flex-container {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  gap: 10px;
}

.switchLabel {
  font-weight: 600;
}

.e-message {
  display: flex;
  align-items: center;
}

.render-mode-info-icon {
  width: 16px;
  height: 16px;
  margin-right: 5px;
}

.sample-container {
  margin-top: 20px;
}

.default-section {
  border: 1px solid #ddd;
  border-radius: 4px;
  background-color: #f9f9f9;
}

.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;
}
</style>

```
