Vue UEditor Wrapper

2.5.6 · maintenance · verified Sun Apr 19

Vue UEditor Wrap is a Vue.js component that integrates Baidu's UEditor, a widely-used rich-text editor in China, into Vue applications. It provides two-way data binding through `v-model`, significantly simplifying UEditor's usage by abstracting away manual initialization and content management (like `getContent` and `setContent` calls). The package is divided into major versions for Vue compatibility: `vue-ueditor-wrap@2.x` supports Vue 2, while `vue-ueditor-wrap@3.x` supports Vue 3. The version 2.5.6 is primarily for Vue 2, with version 3.0.8 being a recent stable release for Vue 3. Its release cadence is irregular, driven by necessary adaptations to new Vue versions and ecosystem changes, rather than active development of the core UEditor. A key differentiator is its ability to dynamically load UEditor's static resources, enabling on-demand loading and mitigating performance impacts. This wrapper addresses the challenge of using an older, feature-rich editor in modern Vue environments, despite the underlying UEditor itself being largely unmaintained by Baidu since 2016.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic integration of `vue-ueditor-wrap` in a Vue 3 application using the Composition API (`<script setup>`). It shows `v-model` for two-way data binding and basic editor configuration, highlighting the necessity of manually placing UEditor's static files and configuring `UEDITOR_HOME_URL`.

<template>
  <div id="app">
    <h1>Vue 3 UEditor Example</h1>
    <p>Editor Content:</p>
    <textarea :value="editorContent" readonly style="width: 100%; height: 100px;"></textarea>
    <vue-ueditor-wrap v-model="editorContent"
                      :config="editorConfig"
                      editor-id="myEditorId">
    </vue-ueditor-wrap>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue';
import VueUeditorWrap from 'vue-ueditor-wrap';

const editorContent = ref('<p>Hello <b>Vue 3</b> and <i>UEditor</i>!</p>');

// Note: UEditor static files must be manually downloaded and placed in the public/UEditor/ directory.
// For example, from https://github.com/fex-team/ueditor/releases
// The UEDITOR_HOME_URL should point to the base path where ueditor.config.js and other files reside.
const editorConfig = {
  UEDITOR_HOME_URL: '/UEditor/', // This path should point to where you placed the UEditor folder
  // Optionally, configure your server-side upload interface here.
  // This example uses a placeholder URL. Implement a secure backend for production.
  serverUrl: 'http://example.com/api/ueditor/upload',
  initialFrameWidth: '100%',
  initialFrameHeight: 300,
  // More UEditor configurations can be added here (e.g., toolbar, plugins)
};

// Optional: Access the UEditor instance after it's ready
const ueditorReady = (editorInstance: any) => {
  console.log('UEditor is ready:', editorInstance);
  // You can interact with the editor instance here, e.g., editorInstance.execCommand('fontsize', '24px');
};

// In a real application, you'd likely use a custom component for the editor
// and pass props/emit events more explicitly.
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>

view raw JSON →