QuillEditor+vue3 本身不支持行高的配置,那么如何配置行高?

通过查阅官方文档和众多资料发现,在QuillEditor的使用中,行高的配置并不像加粗、斜体等样式仅需配置关键词即可,那么QuillEditor的行高如何配置呢?

首先我们仍然要在富文本的配置的modules中写入行高的配置项

复制代码
const myOptions = reactive({
	modules: {
		toolbar: {
			container: [
				['bold', 'italic', 'underline', 'strike'], // 加粗、斜体、下划线、删除线
				[{ header: [1, 2, 3, 4, 5, 6, false] }], // 标题,不同级别的标题
				[{ align: [] }], // 对齐方式
				['blockquote', 'code-block'], // 引用,代码块
				[{ script: 'sub' }, { script: 'super' }], // 上标/下标
				[{ list: 'ordered' }, { list: 'bullet' }], // 有序、无序列表
				[{ indent: '-1' }, { indent: '+1' }], // 缩进
				['link', 'image', 'video'], // 超链接 图片 视频
				[{ direction: 'rtl' }], // 文本方向
				[{ color: [] }, { background: [] }], // 字体颜色和背景色
				[{ size: fontSizeStyle.whitelist }], // 字体大小
				[{ font: fontStyle.whitelist }], // 字体
				[{ lineheight: lineHeight }], // 设置行高
				['clean'], // 清除格式
			],
			handlers: {
				lineheight: (value) => {
					const editor = quillRef.value.getQuill();
					if (value) {
						editor.format('lineHeight', value);
					}
				},
			},
		},
	},
	placeholder: '请输入内容...',
});

同时在modules之外还应设置

复制代码
// 设置行高的配置======start
const lineHeight = ['1', '1.25', '1.5', '1.75', '2.5', '3', '5'];
const parchment = Quill.import('parchment');
const lineHeightConfig = {
	scope: parchment.Scope.INLINE,
	whitelist: lineHeight,
};
const lineHeightStyle = new parchment.Attributor.Style(
	'lineHeight',
	'line-height',
	lineHeightConfig,
);
Quill.register({ 'formats/lineHeight': lineHeightStyle }, true);
// 设置行高的配置======end

行高的样式文件需在style中进行定义,在modules中引入的数值需在css文件中已经定义。

复制代码
.ql-snow .ql-picker.ql-lineheight .ql-picker-label::before {
	content: '行高';
}
.ql-snow .ql-picker.ql-lineheight .ql-picker-item[data-value='1']::before {
	content: '1';
}
.ql-snow .ql-picker.ql-lineheight .ql-picker-item[data-value='1.5']::before {
	content: '1.5';
}
.ql-snow .ql-picker.ql-lineheight .ql-picker-item[data-value='1.75']::before {
	content: '1.75';
}
.ql-snow .ql-picker.ql-lineheight .ql-picker-item[data-value='2']::before {
	content: '2';
}
.ql-snow .ql-picker.ql-lineheight .ql-picker-item[data-value='3']::before {
	content: '3';
}
.ql-snow .ql-picker.ql-lineheight .ql-picker-item[data-value='4']::before {
	content: '4';
}
.ql-snow .ql-picker.ql-lineheight .ql-picker-item[data-value='5']::before {
	content: '5';
}
.ql-snow .ql-picker.ql-lineheight {
	width: 70px;
}
相关推荐
金梦人生4 分钟前
Css性能优化
前端·css
Holin_浩霖5 分钟前
UI设计的底层逻辑:从组件到系统的跃迁
前端
Holin_浩霖5 分钟前
前端开发者的 Web3 全图解实战 二
前端
写代码的皮筏艇5 分钟前
CSS属性继承与特殊值
前端·css
kevlin_coder9 分钟前
🚀 实现同一个滚动区域包含多个虚拟滚动列表
前端·javascript
金梦人生10 分钟前
JS 性能优化
前端·javascript
peachSoda714 分钟前
自定义配置小程序tabbar逻辑思路
javascript·vue.js·微信小程序·小程序
hbqjzx14 分钟前
记录一个自动学习的脚本开发过程
开发语言·javascript·学习
我有一棵树17 分钟前
使用Flex布局实现多行多列,每个列宽度相同
前端·css·html·scss·flex
浪裡遊19 分钟前
React开发模式解析:JSX语法与生命周期管理
前端·javascript·react.js·前端框架·ecmascript