vue-quill-editor 富文本编辑框 —— 自定义行高

本文介绍了如何在vue-quill-editor富文本编辑器中实现自定义行高的功能,包括创建样式文件、导入样式对象、配置工具栏的行高参数及响应函数,以及在编辑器ready事件中注册样式,最后展示了实现后的页面效果和完整代码。
摘要由CSDN通过智能技术生成

一、创建样式文件:

创建一个lineHeight.js,在里实例化一个lineHeightAttributor对象:

import Quill from "quill";
const Parchment = Quill.import("parchment");
class lineHeightAttributor extends Parchment.Attributor.Style {
    }
const lineHeightStyle = new lineHeightAttributor("lineHeight", "line-height", {
   
  scope: Parchment.Scope.INLINE,
  whitelist: ["1", "1.5", "1.75", "2", "3", "4", "5"]
});

export {
    lineHeightStyle }

二、在vue文件中导入样式对象:

import {
    lineHeightStyle } from '@/utils/lineHeight'

三、工具栏配置:

配置行高参数:

const toolbarOptions = [
  [{
    lineheight: ['initial', '1', '1.5', '1.75', '2', '3', '4', '5'] }]
]

配置行高响应函数:

在vue-quill-editor的配置参数里面配置设置行高的响应函数(放到handlers里面):

      // 富文本编辑器配置
      editorOption: {
   
        placeholder: '请在这里输入',
        theme: 'snow', //主题 snow/bubble
        history: {
   
          delay: 1000,
          maxStack: 50,
          userOnly: false
        },
        modules: {
   
          toolbar: {
   
            container: toolbarOptions, //工具栏
            handlers: {
   
              lineheight: (value) => {
   
                if (value) {
   
                  let quill = this.$refs.myQuillEditor.quill;
                  quill.format("lineHeight", value)
                }
              }
            }
          },
        }
      }

四、注册样式:

监听ready事件:

在vue-quill-editor上面监听ready事件(@ready=“onEditorReady($event)”:

<quill-editor ref="myQuillEditor" v-model="content" :options="editorOption" @blur="onEditorBlur($event)" @focus="onEditorFocus($event)" @ready="onEditorReady($event)" />

注册lineHeightStyle

在编辑器的 ready 事件响应函数中注册lineHeightStyle

methods: {
   
    // 准备富文本编辑器
    onEditorReady (quill) 
  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值