Skip to main content
Version: Latest

Vue Component

Unlayer editor is also available as a Vue.js component.

Installation

The easiest way to use it is to install it from npm and include it in your own Vue build process.

Npm

npm install vue-email-editor --save

Yarn

yarn add vue-email-editor

Usage

Next, you'll need to import the Email Editor component to your app.

App.vue

<template>
<div id="app">
<div class="container">
<div id="bar">
<h1>Vue Email Editor (Demo)</h1>

<button v-on:click="saveDesign">Save Design</button>
<button v-on:click="exportHtml">Export HTML</button>
</div>

<EmailEditor ref="emailEditor" v-on:load="editorLoaded" />
</div>
</div>
</template>

<script>
import { EmailEditor } from 'vue-email-editor';

export default {
name: 'app',
components: {
EmailEditor,
},
methods: {
editorLoaded() {
// Pass your template JSON here
// this.$refs.emailEditor.editor.loadDesign({});
},
saveDesign() {
this.$refs.emailEditor.editor.saveDesign((design) => {
console.log('saveDesign', design);
});
},
exportHtml() {
this.$refs.emailEditor.editor.exportHtml((data) => {
console.log('exportHtml', data);
});
},
},
};
</script>

Methods

MethodParamsDescription
loadDesignObject dataTakes the design JSON and loads it in the editor
saveDesignFunction callbackReturns the design JSON in a callback function
exportHtmlFunction callbackReturns the design HTML and JSON in a callback function

See the example source for a reference implementation.

Properties

NameTypeDescriptionDefault Value
minHeightStringMinimum height to initialize the editor with500px
optionsObjectOptions passed to the Unlayer editor instance
toolsObjectConfiguration for the built-in and custom tools
appearanceObjectConfiguration for appearance and theme
localeStringTranslations localeen-US
projectIdIntegerUnlayer project ID (optional)

Here's an example using the above properties...

App.vue

<template>
<div id="app">
<div class="container">
<div id="bar">
<h1>Vue Email Editor (Demo)</h1>

<button v-on:click="saveDesign">Save Design</button>
<button v-on:click="exportHtml">Export HTML</button>
</div>

<EmailEditor
:appearance="appearance"
:min-height="minHeight"
:project-id="projectId"
:locale="locale"
:tools="tools"
:options="options"
ref="emailEditor"
v-on:load="editorLoaded"
/>
</div>
</div>
</template>

<script>
import { EmailEditor } from 'vue-email-editor';

export default {
name: 'app',
components: {
EmailEditor,
},
data() {
return {
minHeight: '1000px',
locale: 'en',
projectId: 0, // replace with your project id
tools: {
// disable image tool
image: {
enabled: false,
},
},
options: {},
appearance: {
theme: 'dark',
panels: {
tools: {
dock: 'right',
},
},
},
};
},
methods: {
editorLoaded() {
// Pass your template JSON here
// this.$refs.emailEditor.editor.loadDesign({});
},
saveDesign() {
this.$refs.emailEditor.editor.saveDesign((design) => {
console.log('saveDesign', design);
});
},
exportHtml() {
this.$refs.emailEditor.editor.exportHtml((data) => {
console.log('exportHtml', data);
});
},
},
};
</script>

Example

See the example source for a reference implementation.