How to Deploy Vue DOCX Editor for Mobile
28 Aug 20264 minutes to read
DOCX Editor component for mobile
At present, Vue DOCX Editor (Document Editor) component is not responsive for mobile, and editing functionalities are not supported in mobile browsers. However, it works properly as a document viewer in mobile browsers.
Hence, it is recommended to switch the DOCX Editor component to read-only in mobile browsers. Also, invoke the fitPage method with FitPageWidth parameter in the document change event to display one full page by adjusting the zoom factor.
The following example code illustrates how to deploy the DOCX Editor component for mobile.
<template>
<div id="app">
<ejs-documenteditorcontainer ref="container" height="590px" :serviceUrl='serviceUrl' :enableToolbar='true'
:documentChange='onDocumentChange'> </ejs-documenteditorcontainer>
</div>
</template>
<script setup>
import { DocumentEditorContainerComponent as EjsDocumenteditorcontainer, Toolbar } from '@syncfusion/ej2-vue-documenteditor';
import { provide, ref } from 'vue';
const container = ref(null);
const serviceUrl = 'https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/';
//Inject require modules.
provide('DocumentEditorContainer', [Toolbar])
const onDocumentChange = function (args) {
//To detect the device
let isMobileDevice = /Android|Windows Phone|webOS/i.test(navigator.userAgent);
if (isMobileDevice) {
container.value.ej2Instances.restrictEditing = true;
setTimeout(() => {
container.value.ej2Instances.documentEditor.fitPage("FitPageWidth");
}, 50);
}
else {
container.value.ej2Instances.restrictEditing = false;
}
}
</script>
<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-lists/styles/material.css';
@import '../node_modules/@syncfusion/ej2-navigations/styles/material.css';
@import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-dropdowns/styles/material.css';
@import "../node_modules/@syncfusion/ej2-vue-documenteditor/styles/material.css";
</style><template>
<div id="app">
<ejs-documenteditorcontainer ref="container" height="590px" :serviceUrl='serviceUrl' :enableToolbar='true'
:documentChange='onDocumentChange'> </ejs-documenteditorcontainer>
</div>
</template>
<script>
import { DocumentEditorContainerComponent, Toolbar } from '@syncfusion/ej2-vue-documenteditor';
export default {
components: {
'ejs-documenteditorcontainer': DocumentEditorContainerComponent
},
data() {
return { serviceUrl: 'https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/' }
},
provide: {
//Inject require modules.
DocumentEditorContainer: [Toolbar]
},
methods: {
onDocumentChange: function (args) {
//To detect the device
let isMobileDevice = /Android|Windows Phone|webOS/i.test(navigator.userAgent);
if (isMobileDevice) {
this.$refs.container.ej2Instances.restrictEditing = true;
setTimeout(() => {
this.$refs.container.ej2Instances.documentEditor.fitPage("FitPageWidth");
}, 50);
}
else {
this.$refs.container.ej2Instances.restrictEditing = false;
}
}
}
}
</script>
<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-lists/styles/material.css';
@import '../node_modules/@syncfusion/ej2-navigations/styles/material.css';
@import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-dropdowns/styles/material.css';
@import "../node_modules/@syncfusion/ej2-vue-documenteditor/styles/material.css";
</style>The Web API hosted link
https://document.syncfusion.com/web-services/docx-editor/api/documenteditor/utilized in the DOCX Editor’s serviceUrl property is intended solely for demonstration and evaluation purposes. For production deployment, please host your own web service with your required server configurations. You can refer and reuse the GitHub Web Service example or Docker image for hosting your own web service and use for the serviceUrl property.
You can download the complete working example from this GitHub location
You can use the
restrictEditingin DocumentEditorContainer andisReadOnlyin DocumentEditor based on your requirement to change the component to read-only mode.