Skip to main content
Version: Latest

Vue Reference

The Dragble editor can be embedded in Vue 3 using the CDN-based SDK.

Adding the SDK

Add the script tag to your index.html:

<script src="https://sdk.dragble.com/latest/dragble-sdk.min.js"></script>

Usage with Vue

Use Vue's lifecycle hooks to initialize and clean up the editor:

<script setup lang="ts">
import { ref, onMounted, onUnmounted } from "vue";

const containerRef = ref<HTMLDivElement | null>(null);
const editor = ref<DragbleEditorInstance | null>(null);

onMounted(() => {
if (!containerRef.value) return;

const pexEditor = dragble.createEditor({
containerId: "editor-container",
user: { id: "user-1", name: "Jane", email: "jane@example.com" },
appearance: { theme: "light" },
});

pexEditor.addEventListener("ready", () => {
console.log("Editor ready");
});

pexEditor.addEventListener("change", (design: any) => {
console.log("Changed", design);
});

editor.value = pexEditor;
});

onUnmounted(() => {
editor.value?.destroy();
});

const handleExport = async () => {
if (!editor.value) return;
const html = await editor.value.exportHtml();
console.log("Exported HTML:", html);
};
</script>

<template>
<div>
<button @click="handleExport">Export HTML</button>
<div id="editor-container" ref="containerRef" style="height: 600px" />
</div>
</template>

Editor Instance Methods

MethodSignatureDescription
loadDesign(design: DesignJson) => voidLoad a design.
getDesign() => DesignJsonGet the current design JSON.
exportHtml() => Promise<ExportHtmlData>Export as HTML.
exportImage(options?: ExportImageOptions) => Promise<ExportImageData>Export as image.
exportPdf(options?: ExportPdfOptions) => Promise<ExportPdfData>Export as PDF.
undo() => voidUndo last action.
redo() => voidRedo last action.
setViewMode(mode: ViewMode) => voidSwitch desktop/tablet/mobile.
setTheme(theme: ThemeMode) => voidSwitch light/dark theme.
showPreview() => voidOpen preview modal.
hidePreview() => voidClose preview modal.
destroy() => voidDestroy the editor instance.
addEventListener(event: string, handler: Function) => voidSubscribe to events.
removeEventListener(event: string, handler: Function) => voidUnsubscribe from events.

TypeScript

Add type declarations in your env.d.ts:

declare const dragble: {
createEditor(config: DragbleConfig): DragbleEditorInstance;
};
warning

Set an explicit height on the editor container. The editor fills its parent and requires a defined height to render.