样式设置,注意:不能加scoped:
.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;
}
创建一个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 }
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/bubblehistory: {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)}}}},}}
在vue-quill-editor上面监听ready事件(@ready=“onEditorReady($event)”:
在编辑器的 ready 事件响应函数中注册lineHeightStyle:
import Quill from 'quill'
methods: {// 准备富文本编辑器onEditorReady (quill) {Quill.register({ 'formats/lineHeight': lineHeightStyle }, true)}
}