Skip to content
Integration guide ยท Nuxt 3 and 4 · Vue 3.4+

Add a WYSIWYG editor to Nuxt

Use the Vue component with v-model, save through a Nitro API route and receive uploads with readMultipartFormData. No API key, MIT licensed.

Step 1: Install the packages

The Vue component works with Vue 3.3 and later. It creates the editor in onMounted, so server rendering outputs an empty element.

npm install wds-editor wds-editor-vue
npm install sanitize-html && npm install -D @types/sanitize-html

Step 2: Create an editor component

Wrap the editor in <ClientOnly> so the server and the browser render the same markup, and pass the HTML through v-model.

<script setup lang="ts">
import { WdsEditor } from 'wds-editor-vue';
import 'wds-editor/style.css';

const html = defineModel<string>({ default: '' });
const options = {
  preset: 'standard' as const,
  height: 480,
  fileManager: { listUrl: '/api/files', uploadUrl: '/api/files' }
};
</script>

<template>
  <ClientOnly>
    <WdsEditor v-model="html" :options="options" />
  </ClientOnly>
</template>

Step 3: Save through an API route

Post the HTML with $fetch and clean it in a Nitro handler before it reaches the database.

<!-- pages/posts/new.vue -->
<script setup lang="ts">
const body = ref('');
async function save() {
  await $fetch('/api/posts', { method: 'POST', body: { body: body.value } });
}
</script>

<template>
  <form @submit.prevent="save">
    <PostEditor v-model="body" />
    <button type="submit">Save</button>
  </form>
</template>

// server/api/posts.post.ts
import sanitizeHtml from 'sanitize-html';

export default defineEventHandler(async (event) => {
  const { body } = await readBody<{ body?: string }>(event);
  const clean = sanitizeHtml(body ?? '', {
    allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img']),
    allowedAttributes: {
      ...sanitizeHtml.defaults.allowedAttributes,
      '*': ['class', 'style', 'data-*'],   // data-* keeps checklists and @mentions
      img: ['src', 'alt', 'width', 'height']
    }
  });
  // await db.insert(posts).values({ body: clean });
  return { ok: true };
});

Step 4: Add the upload routes

Two Nitro handlers list and receive files. They write to public/uploads, which works in development; a production build serves only the files that existed at build time, so store uploads in object storage or a folder you serve yourself.

// server/api/files.get.ts
import { mkdir, readdir, stat } from 'node:fs/promises';
import { extname, join } from 'node:path';

const dir = join(process.cwd(), 'public', 'uploads');
const allowed = new Set(['.jpg', '.jpeg', '.png', '.gif', '.webp', '.pdf']);

export default defineEventHandler(async () => {
  await mkdir(dir, { recursive: true });
  const names = (await readdir(dir)).filter((n) => allowed.has(extname(n).toLowerCase()));
  const files = await Promise.all(names.map(async (name) => ({ url: `/uploads/${name}`, name, size: (await stat(join(dir, name))).size })));
  return { files };
});

// server/api/files.post.ts
import { mkdir, writeFile } from 'node:fs/promises';
import { extname, join } from 'node:path';
import { randomUUID } from 'node:crypto';

const dir = join(process.cwd(), 'public', 'uploads');
const allowed = new Set(['.jpg', '.jpeg', '.png', '.gif', '.webp', '.pdf']);

export default defineEventHandler(async (event) => {
  // Check the session here before accepting files
  const file = (await readMultipartFormData(event))?.find((p) => p.name === 'file' && p.filename);
  const ext = extname(file?.filename ?? '').toLowerCase();
  if (!file || !allowed.has(ext) || file.data.length > 10 * 1024 * 1024) {
    setResponseStatus(event, 400);
    return { error: 'Images or PDF files up to 10 MB.' };
  }
  const name = randomUUID() + ext;
  await mkdir(dir, { recursive: true });
  await writeFile(join(dir, name), file.data);
  return { url: `/uploads/${name}`, name };
});

Good to know

  • Register the component globally with a plugin: nuxtApp.vueApp.use(WdsEditorPlugin) in plugins/wds-editor.client.ts.
  • Show saved HTML with v-html only after it was cleaned on the server.
  • Comment boxes: preset: 'basic' with maxLength, without the file manager.
  • Every option, the toolbar items and the file manager JSON format are in the documentation; the server examples add folders, rename, delete and an AI endpoint.

FAQ

Does WDS Editor work with Nuxt server-side rendering?

Yes. The Vue component creates the editor in onMounted, so the server renders an empty element. Wrapping it in ClientOnly keeps the server and browser markup the same.

Does v-model work with WDS Editor in Nuxt?

Yes. The component supports v-model; the value is the clean HTML, updated after every change. Setting the model from outside replaces the content.

Can I use WDS Editor with Nuxt Content or a headless CMS?

Yes. The editor outputs plain HTML, and getMarkdown() returns Markdown if your content is stored as Markdown files.

Guides for other frameworks

Try WDS Editor in your browser

Free and MIT licensed, with a file manager, tables, Markdown and code blocks built in. No key, no account, no load limits.