Skip to content

Video, Audio and Embeds in the Vue 3 Editor ​

The media plugin lets a Vue 3 <Editor> insert HTML5 video, audio, or a sandboxed HTTPS iframe from a URL. Turn it on in the object you bind to :init; the inserted <video>, <audio>, or <iframe> tag then becomes part of the v-model HTML. Raw embed code and scripts are not accepted.

For ordinary hyperlinks and bookmarks, see links and anchors.

Configuration ​

vue
<script setup lang="ts">
import { shallowRef } from 'vue';
import { Editor, type EditorInit } from '@erag/text-editor-vue';

const content = shallowRef('');

const editorConfig: EditorInit = {
    plugins: ['media'],
    menubar: ['insert'],
    toolbar: 'media',
};
</script>

<template>
    <Editor v-model="content" :init="editorConfig" />
</template>

If you provide an explicit plugin array, include media or its toolbar and Insert-menu controls are filtered out.

Insert media ​

Open Insert → Media or click the toolbar media button, then choose a type:

  • Video inserts <video controls> and accepts width, height, and an optional safe poster URL.
  • Audio inserts <audio controls> from a direct source URL.
  • Secure embed inserts an <iframe> only for an https:// source, with a restrictive sandbox and an accessible title. For a full YouTube walkthrough, including a Laravel check that only lets trusted video hosts through, see embedding YouTube videos in a rich text editor.
html
<video src="/media/demo.mp4" width="640" height="360" controls></video>

<audio src="/media/demo.mp3" controls></audio>

<iframe
    src="https://www.youtube.com/embed/example"
    width="640"
    height="360"
    sandbox="allow-same-origin allow-presentation"
    title="Embedded media"
></iframe>

The media dialog accepts URLs, not pasted HTML. Unsafe protocols and non-HTTPS iframe sources are rejected. More on this in security and sanitization. relativeUrls: false can be used when your application requires absolute media URLs.