• vue3使用QuillEditor


     1.安装

    npm install @vueup/vue-quill@alpha --save

    2.引入

            全局引入

    1. import { QuillEditor } from '@vueup/vue-quill';
    2. import '@vueup/vue-quill/dist/vue-quill.snow.css';
    3. app.component('QuillEditor', QuillEditor);

            部分引入

    1. import { QuillEditor } from '@vueup/vue-quill'
    2. import '@vueup/vue-quill/dist/vue-quill.snow.css';
    3. export default {
    4. components: {
    5. QuillEditor
    6. }
    7. }

    3.使用

     HTML部分:

    1. <quill-editor
    2. class="ql-editor"
    3. v-model="content"
    4. ref="myQuillEditor"
    5. :options="editorOption"
    6. @blur="onEditorBlur($event)"
    7. @focus="onEditorFocus($event)"
    8. @change="onEditorChange($event)"
    9. />

    js部分:

    1. const content = '`

      这是 vue-quill-editor 的内容!

      `'
      ;
    2. const editorOption = {
    3. modules: {
    4. toolbar: [
    5. ['bold', 'italic', 'underline', 'strike'], // 加粗 斜体 下划线 删除线
    6. ['blockquote', 'code-block'], // 引用 代码块
    7. [{ header: 1 }, { header: 2 }], // 1、2 级标题
    8. [{ list: 'ordered' }, { list: 'bullet' }], // 有序、无序列表
    9. [{ script: 'sub' }, { script: 'super' }], // 上标/下标
    10. [{ indent: '-1' }, { indent: '+1' }], // 缩进
    11. [{ direction: 'rtl' }], // 文本方向
    12. [{ size: ['12px', false, '16px', '18px', '20px', '30px'] }], // 字体大小
    13. [{ header: [1, 2, 3, 4, 5, 6, false] }], // 标题
    14. [{ color: [] }, { background: [] }], // 字体颜色、字体背景颜色
    15. [{ font: [false, 'SimSun', 'SimHei', 'Microsoft-YaHei', 'KaiTi', 'FangSong', 'Arial'] }], // 字体种类
    16. [{ align: [] }], // 对齐方式
    17. ['clean'], // 清除文本格式
    18. ['link', 'image', 'video'], // 链接、图片、视频
    19. ],
    20. },
    21. placeholder: '请输入正文',
    22. };
    23. const content = ref('`

      这是 vue-quill-editor 的内容!

      `'
      );
    24. const editorOption = {
    25. modules: {
    26. toolbar: [
    27. ['bold', 'italic', 'underline', 'strike'], // 加粗 斜体 下划线 删除线
    28. ['blockquote', 'code-block'], // 引用 代码块
    29. [{ header: 1 }, { header: 2 }], // 1、2 级标题
    30. [{ list: 'ordered' }, { list: 'bullet' }], // 有序、无序列表
    31. [{ script: 'sub' }, { script: 'super' }], // 上标/下标
    32. [{ indent: '-1' }, { indent: '+1' }], // 缩进
    33. [{ direction: 'rtl' }], // 文本方向
    34. [{ size: ['12px', false, '16px', '18px', '20px', '30px'] }], // 字体大小
    35. [{ header: [1, 2, 3, 4, 5, 6, false] }], // 标题
    36. [{ color: [] }, { background: [] }], // 字体颜色、字体背景颜色
    37. [{ font: [false, 'SimSun', 'SimHei', 'Microsoft-YaHei', 'KaiTi', 'FangSong', 'Arial'] }], // 字体种类
    38. [{ align: [] }], // 对齐方式
    39. ['clean'], // 清除文本格式
    40. ['link', 'image', 'video'], // 链接、图片、视频
    41. ],
    42. },
    43. placeholder: '请输入正文',
    44. };
    45. // 失去焦点事件
    46. const onEditorBlur = (quill) => {
    47. console.log('editor blur!', quill);
    48. };
    49. // 获得焦点事件
    50. const onEditorFocus = (quill) => {
    51. console.log('editor focus!', quill);
    52. };
    53. // 准备富文本编辑器
    54. const onEditorReady = (quill) => {
    55. console.log('editor ready!', quill);
    56. };
    57. // 内容改变事件
    58. const onEditorChange = ({ quill, html, text }) => {
    59. console.log('editor change!', quill, html, text);
    60. content.value = html;
    61. };

  • 相关阅读:
    第19集丨本来无一物,何处惹尘埃
    【kubernetes】kubernetes中的Controller
    AD教程 (十八)导入常见报错解决办法(unkonw pin及绿色报错等)
    PyCharm 虚拟环境搭建
    Dart:补充
    重链剖分链加与极值
    【每日一题】打卡 47
    一文详解CAD与图新地球软件中提取高程点的方法图新地球
    【YOLO5Face】《YOLO5Face:Why Reinventing a Face Detector》
    Mysql - 分库分表
  • 原文地址:https://blog.csdn.net/m0_45827438/article/details/133995096