Vue uses rich text boxes, element-tiptap is preferred

element-tiptapGitHub address: https://github.com/Leecason/element-tiptap/blob/master/README_ZH.md
1. As usual, first npm the third-party plug-in

npm install --save element-tiptap

2. Choose one of local registration and global registration (I use local registration, after all, it is rarely used, and it can also be packaged separately, and it can be called wherever it is needed) 2.1. Let’s talk about global registration first
.

import {
    
     ElementTiptapPlugin } from 'element-tiptap';
// import element-tiptap 样式
import 'element-tiptap/lib/index.css';
// 安装 element-tiptap 插件
Vue.use(ElementTiptapPlugin, {
    
    
  lang: 'zh', // 设置语言为中文
});

2.2. Partial registration and use (just copy my whole copy in the past, it is enough)

<template>
  <div>
    <el-tiptap v-model="content" :extensions="extensions" lang="zh" />
  </div>
</template>

<script>
import 'element-tiptap/lib/index.css'
import {
    
    
  ElementTiptap,
  // 需要的 extensions
  Doc,
  Text,
  Paragraph,
  Heading,
  Bold,
  Underline,
  Italic,
  Strike,
  ListItem,
  BulletList,
  OrderedList,
  Link,
  Image,
  CodeBlock,
  Blockquote,
  TodoItem,
  TodoList,
  TextAlign,
  FontSize,
  FontType,
  Fullscreen,
  TextHighlight,
  TextColor,
  FormatClear,
  Table,
  TableHeader,
  TableCell,
  TableRow,
  History,
  TrailingNode,
  HardBreak,
  HorizontalRule,
  LineHeight,
  Indent
} from 'element-tiptap';

export default {
    
    
  data () {
    
    
    // 编辑器的 extensions
    // 它们将会按照你声明的顺序被添加到菜单栏和气泡菜单中
    return {
    
    
      extensions: [
        new Doc(), // 必须项
        new Text(), // 必须项
        new Paragraph(), // 必须项
        new Heading({
    
     level: 6 }), // 标题
        new Bold({
    
     bubble: true }), // 加粗 bubble: true 在气泡菜单中渲染菜单按钮
        new Underline({
    
     bubble: true, menubar: false }), // 下划线 bubble: true, menubar: false 在气泡菜单而不在菜单栏中渲染菜单按钮
        new Italic({
    
     bubble: true }), // 斜体
        new Strike({
    
     bubble: true }), // 删除线
        new ListItem(), // 使用列表必须项
        new BulletList({
    
     bubble: true }), // 无序列表
        new OrderedList({
    
     bubble: true }), // 有序列表
        new Link(), // 链接
        new Image(), // 图片
        new CodeBlock({
    
     bubble: true }), // 代码块
        new Blockquote(), // 引用
        new TodoItem(), // 任务列表必须项
        new TodoList(), // 任务列表
        new TextAlign({
    
     bubble: true }), // 文本对齐方式
        new FontSize({
    
     bubble: true }), // 字号
        new FontType({
    
     bubble: true }), // 字体
        new Fullscreen(), // 全屏
        new TextHighlight({
    
     bubble: true }), // 文本高亮
        new TextColor({
    
     bubble: true }), // 文本颜色
        new FormatClear({
    
     bubble: true }), // 清除格式
        new Table({
    
     resizable: true }), // 表格
        new TableHeader(), // 表格必须项
        new TableCell(), // 表格必须项
        new TableRow(), // 表格必须项
        new History(), // 撤销
        new TrailingNode(), // 重做
        new HardBreak(), // 分割线
        new HorizontalRule(), // 行距
        new LineHeight(), // 增加缩进
        new Indent() // 减少缩进
      ],
      // 编辑器的内容
      content: `
        <h1>Heading</h1>
        <p>This Editor is awesome!</p>
      `,
    };
  },
  components: {
    
    
    'el-tiptap': ElementTiptap,
  },
}
</script>

Guess you like

Origin blog.csdn.net/weixin_44949068/article/details/128330053