JS部分:
//引入Qill插件 import Quill from "quill"; // 自定义字体 let fontFamily = ['SimSun', 'SimHei', 'Microsoft-YaHei', 'KaiTi', 'FangSong', 'Arial', 'pingfang']; Quill.imports['formats/font'].whitelist = fontFamily; Quill.register(Quill.imports['formats/font']) // 自定义文字大小 let fontSize = ['10px', '12px', '14px', '16px', '20px', '24px', '36px'] Quill.imports['attributors/style/size'].whitelist = fontSize; Quill.register(Quill.imports['attributors/style/size']); const toolbarOptions = [ [ "bold", "italic", "underline", "strike", "blockquote", "code-block", { header: 1 }, { header: 2 }, { list: "ordered" }, { list: "bullet" }, { indent: "-1" }, { indent: "+1" }, { script: "sub" }, // 下标 { script: "super" }, // 上标 { align: [] }, { color: [] }, { background: [] }, "link", "image", ], [{ size: fontSize }], // 文字大小 [{ header: [1, 2, 3, 4, 5, 6, false] }], // 标题 [{ font: fontFamily }], // 字体 ];
css部分:
::v-deep{ /* 文字大小 */ .ql-snow .ql-picker.ql-size .ql-picker-label[data-value='10px']::before, .ql-snow .ql-picker.ql-size .ql-picker-item[data-value='10px']::before { content: '10px'; } .ql-snow .ql-picker.ql-size .ql-picker-label[data-value='12px']::before, .ql-snow .ql-picker.ql-size .ql-picker-item[data-value='12px']::before { content: '12px'; } .ql-snow .ql-picker.ql-size .ql-picker-label[data-value='14px']::before, .ql-snow .ql-picker.ql-size .ql-picker-item[data-value='14px']::before { content: '14px'; } .ql-snow .ql-picker.ql-size .ql-picker-label[data-value='16px']::before, .ql-snow .ql-picker.ql-size .ql-picker-item[data-value='16px']::before { content: '16px'; } .ql-snow .ql-picker.ql-size .ql-picker-label[data-value='20px']::before, .ql-snow .ql-picker.ql-size .ql-picker-item[data-value='20px']::before { content: '20px'; } .ql-snow .ql-picker.ql-size .ql-picker-label[data-value='24px']::before, .ql-snow .ql-picker.ql-size .ql-picker-item[data-value='24px']::before { content: '24px'; } .ql-snow .ql-picker.ql-size .ql-picker-label[data-value='36px']::before, .ql-snow .ql-picker.ql-size .ql-picker-item[data-value='36px']::before { content: '36px'; } /* 字体 */ .ql-snow .ql-picker.ql-font .ql-picker-label[data-value='SimSun']::before, .ql-snow .ql-picker.ql-font .ql-picker-item[data-value='SimSun']::before { content: '宋体'; font-family: 'SimSun' !important; } .ql-snow .ql-picker.ql-font .ql-picker-label[data-value='SimHei']::before, .ql-snow .ql-picker.ql-font .ql-picker-item[data-value='SimHei']::before { content: '黑体'; font-family: 'SimHei'; } .ql-snow .ql-picker.ql-font .ql-picker-label[data-value='Microsoft-YaHei']::before, .ql-snow .ql-picker.ql-font .ql-picker-item[data-value='Microsoft-YaHei']::before { content: '微软雅黑'; font-family: '微软雅黑'; } .ql-snow .ql-picker.ql-font .ql-picker-label[data-value='KaiTi']::before, .ql-snow .ql-picker.ql-font .ql-picker-item[data-value='KaiTi']::before { content: '楷体'; font-family: 'KaiTi' !important; } .ql-snow .ql-picker.ql-font .ql-picker-label[data-value='FangSong']::before, .ql-snow .ql-picker.ql-font .ql-picker-item[data-value='FangSong']::before { content: '仿宋'; font-family: 'FangSong'; } .ql-snow .ql-picker.ql-font .ql-picker-label[data-value='Arial']::before, .ql-snow .ql-picker.ql-font .ql-picker-item[data-value='Arial']::before { content: 'Arial'; font-family: 'Arial'; } .ql-snow .ql-picker.ql-font .ql-picker-label[data-value='pingfang']::before, .ql-snow .ql-picker.ql-font .ql-picker-item[data-value='pingfang']::before { content: '苹方'; font-family: '苹方'; } // 设置每个字体的css字体样式 .ql-font-SimSun { font-family: 'SimSun'; } .ql-font-SimHei { font-family: 'SimHei'; } .ql-font-Microsoft-YaHei { font-family: '微软雅黑'; } .ql-font-KaiTi { font-family: 'KaiTi'; } .ql-font-FangSong { font-family: 'FangSong'; } .ql-font-Arial { font-family: 'Arial'; } .ql-font-pingfang { font-family: '苹方'; } /* 标题 */ .ql-snow .ql-picker.ql-header .ql-picker-label::before, .ql-snow .ql-picker.ql-header .ql-picker-item::before { content: "文本" !important; } .ql-snow .ql-picker.ql-header .ql-picker-label[data-value="1"]::before, .ql-snow .ql-picker.ql-header .ql-picker-item[data-value="1"]::before { content: "标题1" !important; } .ql-snow .ql-picker.ql-header .ql-picker-label[data-value="2"]::before, .ql-snow .ql-picker.ql-header .ql-picker-item[data-value="2"]::before { content: "标题2" !important; } .ql-snow .ql-picker.ql-header .ql-picker-label[data-value="3"]::before, .ql-snow .ql-picker.ql-header .ql-picker-item[data-value="3"]::before { content: "标题3" !important; } .ql-snow .ql-picker.ql-header .ql-picker-label[data-value="4"]::before, .ql-snow .ql-picker.ql-header .ql-picker-item[data-value="4"]::before { content: "标题4" !important; } .ql-snow .ql-picker.ql-header .ql-picker-label[data-value="5"]::before, .ql-snow .ql-picker.ql-header .ql-picker-item[data-value="5"]::before { content: "标题5" !important; } .ql-snow .ql-picker.ql-header .ql-picker-label[data-value="6"]::before, .ql-snow .ql-picker.ql-header .ql-picker-item[data-value="6"]::before { content: "标题6" !important; } }