Install Element Tiptap via NPM
nextYou can install element-tiptap using either yarn or npm.
yarn add element-tiptapor
npm install --save element-tiptaprepository·next·Indexed 23 days ago
https://github.com/leecason/element-tiptapA modern WYSIWYG rich-text editor for Vue 3 that combines Tiptap 2 with Element Plus UI components. It features a highly extensible system using an extensions array to define editor capabilities and toolbar buttons, supporting both HTML and JSON output formats. The library includes built-in i18n support for multiple languages and provides a set of configurable props for dimensions, read-only mode, and spellcheck.
You can install element-tiptap using either yarn or npm.
yarn add element-tiptapor
npm install --save element-tiptapTo use the el-tiptap component globally, install the plugin and its required styles in your main entry file.
Note: You must also have element-plus installed as it is a peer dependency.
import { createApp } from 'vue';
import App from './App.vue';
import ElementPlus from 'element-plus';
import ElementTiptapPlugin from 'element-tiptap';
// import element-tiptap 样式
import 'element-tiptap/lib/style.css';
// 安装 ElementUI 插件
app.use(ElementPlus);
// 安装 element-tiptap 插件
app.use(ElementTiptapPlugin);
// 现在你已经在全局注册了 `el-tiptap` 组件。
app.mount('#app');If you prefer not to register the component globally, you can import ElementTiptap directly within your component's <script setup> block.
<template>
<el-tiptap ...><el-tiptap>
</template>
<script setup>
import { ElementTiptap } from 'element-tiptap';
</script>You can install element-tiptap using yarn or npm.
To register the el-tiptap component globally in your Vue 3 application, install the package and use the ElementTiptapPlugin in your main entry file. You must also import the library's styles.
Alternatively, you can import the ElementTiptap component directly for local use in your components.
yarn add element-tiptap
# or
npm install --save element-tiptapTo use the el-tiptap component globally, register the plugin in your Vue app instance and ensure you import the required CSS.
import { createApp } from 'vue';
import App from './App.vue';
import ElementPlus from 'element-plus';
import ElementTiptapPlugin from 'element-tiptap';
import 'element-tiptap/lib/style.css';
const app = createApp(App);
app.use(ElementPlus);
app.use(ElementTiptapPlugin);
app.mount('#app');import { createApp } from 'vue';
import App from './App.vue';
import ElementPlus from 'element-plus';
import ElementTiptapPlugin from 'element-tiptap';
// import ElementTiptap's styles
import 'element-tiptap/lib/style.css';
const app = createApp(App);
// use ElementPlus's plugin
app.use(ElementPlus);
// use this package's plugin
app.use(ElementTiptapPlugin);
// Now you register `'el-tiptap'` component globally.
app.mount('#app');The Menubar component relies on a specific pattern within extension options to render toolbar buttons. For an extension to appear in the Menubar, its options object must include a button property which is a function.
This function is called by the Menubar component and receives an object containing:
editor: The Tiptap Editor instance.t: The translation function (injected from the parent context).extension: The extension instance itself.The button function must return either a single component specification object or an array of component specification objects. These objects are then used with v-bind to pass props and events to the rendered component.
You can define custom command buttons for the MenuBubble by configuring the bubble option in your Tiptap extensions.
An extension's bubble option should be a function that returns a component specification (or an array of specifications). This function receives an object containing the editor, translation function t, and the extension itself.
Example of the expected return structure for the button function:
// Inside an extension configuration
options: {
bubble: ({ editor, t, extension }) => ({
component: MyCustomButtonComponent,
componentProps: {
// props passed to MyCustomButtonComponent
},
componentEvents: {
// events for MyCustomButtonComponent
}
})
}ElementTiptapPlugin. This plugin registers the editor component globally under two names: <element-tiptap> and <el-tiptap>.The el-tiptap component uses v-model:content for two-way data binding. You must provide an array of extensions to define the editor's capabilities and the toolbar buttons. Extensions are added to the menubar and bubble menu in the order they are declared.
Some extensions can be configured using .configure(). For example, Bold.configure({ bubble: true }) enables the command button in the bubble menu.
<template>
<el-tiptap v-model:content="content" :extensions="extensions" />
</template>
<script setup>
import { ref } from 'vue';
import {
// necessary extensions
Doc,
Text,
Paragraph,
Heading,
Bold,
Underline,
Italic,
Strike,
BulletList,
OrderedList,
} from 'element-tiptap';
// editor extensions
// they will be added to menubar and bubble menu by the order you declare.
const extensions = [
Doc,
Text,
Paragraph,
Heading.configure({ level: 5 }),
Bold.configure({ bubble: true }), // render command-button in bubble menu.
Underline.configure({ bubble: true, menubar: false }), // render command-button in bubble menu but not in menubar.
Italic,
Strike,
BulletList,
OrderedList,
];
// editor's content
const content = ref(`
<h1>Heading</h1>
<p>This Editor is awesome!</p>
`);
</script>To use the editor, provide a v-model:content for data binding and an extensions array to define the available tools. Extensions are added to the menubar and bubble menu in the order they are declared.
You can use .configure() on extensions to customize their behavior, such as enabling the bubble menu (bubble: true) or disabling them in the menubar (menubar: false).
<template>
<el-tiptap v-model:content="content" :extensions="extensions" />
</template>
<script setup>
import { ref } from 'vue';
import {
// 需要的 extensions
Doc,
Text,
Paragraph,
Heading,
Bold,
Underline,
Italic,
Strike,
BulletList,
OrderedList,
} from 'element-tiptap';
// 编辑器的 extensions
// 它们将会按照你声明的顺序被添加到菜单栏和气泡菜单中
const extensions = [
Doc,
Text,
Paragraph,
Heading.configure({ level: 5 }),
Bold.configure({ bubble: true }), // 在气泡菜单中渲染菜单按钮
Underline.configure({ bubble: true, menubar: false }), // 在气泡菜单而不在菜单栏中渲染菜单按钮
Italic,
Strike,
BulletList,
OrderedList,
];
// 编辑器的内容
const content = ref(`
<h1>Heading</h1>
<p>This Editor is awesome!</p>
`);
</script>To change the editor's language, import a locale object from element-tiptap/lib/locales/ and pass it to the locale prop.
Supported languages include: en (default), zh, pl, ru, de, ko, es, zh_tw, fr, pt_br, nl, he.
<template>
<el-tiptap :locale="en"></el-tiptap>
</template>
<script setup>
import { ElementTiptap } from 'element-tiptap';
import en from 'element-tiptap/lib/locales/en';
</script>width and height props accept strings (with units) or numbers. If a number is provided, the default unit is px.