• 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. };

  • 相关阅读:
    【Vue五分钟】五分钟让你了解vue组件的层级关系
    Zen of Python(python之禅)
    Anaconda删除虚拟环境
    ES索引Json格式字段设计
    Kubernetes(k8s)的三种资源管理方式
    C# 经典:ref 和 out 的区别详解
    process.env环境变量配置方式(配置环境变量区分开发环境和生产环境)
    Kubernetes之Pod初始化容器
    【计算机毕业设计】094图书馆自习室座位预约管理微信小程序
    【AWS系列】boto3入门-上篇
  • 原文地址:https://blog.csdn.net/m0_45827438/article/details/133995096