Skip to content

Rich Text Component

This guide explains how to integrate and use the open-source rich text component wangeditor that has been secondarily encapsulated in FormCreate. Through this guide, you'll learn how to install, configure, generate, and use rich text components in different business scenarios.

Note

When customizing rich text functionality, personalized settings can be completed through config and init parameters. For specific parameters, please refer to the rich text component's official documentation. The internal version used is 4.x

Example

The following image shows an example of a simple rich text editor:

editor

Installation

You can install the rich text component in the following ways:

Node Environment

sh
npm install @form-create/component-wangeditor^3

Browser Environment

html
<script src="https://cdn.jsdelivr.net/npm/@form-create/component-wangeditor@^3/dist/index.js"></script>

Import and Mount Component

Node Environment

js
import FcEditor from "@form-create/component-wangeditor";
app.component('fcEditor', FcEditor);
// Or local mounting
formCreate.component('fcEditor', FcEditor);

Browser Environment

js
var FcEditor = window.FcEditor;
formCreate.component('fcEditor', FcEditor);

Generating Rich Text Component

Using rich text components in forms is very simple. The following is an example of generating a rich text component:

js
 {
    type: 'fcEditor',
    field: 'editor',
    title: 'Rich Text Editor',
    value: '<b>@form-create/component-wangeditor</b>',
    props: {
      init(editor) {
          // Callback during initialization
          console.log('Editor initialized', editor);
      },
      config: {
          placeholder: 'Enter content...',
              height: 300
      },
      disabled: false
    }
}

Configuration

PropertyTypeDescription
v-modelstringRich text content
initFunctionInitialize wangEditor
configobjectSet wangEditor component's config
disabledbooleanDisable rich text component

Custom Configuration and Plugin Extension

Rich text components support highly customizable configuration and plugin extensions. You can customize toolbars, format options, etc. through the config property:

js
const rule = {
    type: 'fcEditor',
    field: 'customEditor',
    title: 'Custom Rich Text Editor',
    props: {
      config: {
        menus: ['head', 'bold', 'italic', 'underline', 'link', 'list', 'image'],
        uploadImgServer: '/api/uploadImage'
      }
    }
}

In this example, we customized the rich text editor's toolbar and set the image upload server.

FormCreate is an open-source project released under the MIT License. Free for personal and commercial use.