quill-options.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. const toolbarOptions = [
  2. ['bold', 'italic', 'underline', 'strike'], // 加粗 斜体 下划线 删除线
  3. ['blockquote', 'code-block'], // 引用 代码块
  4. [{ header: 1 }, { header: 2 }], // 1、2 级标题
  5. [{ list: 'ordered' }, { list: 'bullet' }], // 有序、无序列表
  6. [{ script: 'sub' }, { script: 'super' }], // 上标/下标
  7. [{ indent: '-1' }, { indent: '+1' }], // 缩进
  8. // [{'direction': 'rtl'}], // 文本方向
  9. [{ size: ['small', false, 'large', 'huge'] }], // 字体大小
  10. [{ header: [1, 2, 3, 4, 5, 6, false] }], // 标题
  11. [{ color: [] }, { background: [] }], // 字体颜色、字体背景颜色
  12. [{ font: [] }], // 字体种类
  13. [{ align: [] }], // 对齐方式
  14. ['clean'], // 清除文本格式
  15. ['link', 'image', 'video'] // 链接、图片、视频
  16. ]
  17. export default {
  18. theme: 'snow',
  19. placeholder: '请输入文章内容',
  20. modules: {
  21. toolbar: {
  22. container: toolbarOptions,
  23. // container: "#toolbar",
  24. handlers: {
  25. image: function (value) {
  26. if (value) {
  27. // 触发input框选择图片文件
  28. document.querySelector('.avatar-uploader input').click()
  29. } else {
  30. this.quill.format('image', false)
  31. }
  32. },
  33. link: function (value) {
  34. if (value) {
  35. const href = prompt('注意!只支持公众号图文链接')
  36. this.quill.format('link', href)
  37. } else {
  38. this.quill.format('link', false)
  39. }
  40. }
  41. }
  42. }
  43. }
  44. }