index.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <div class="rich-editor">
  3. <QuillEditor
  4. ref="editorRef"
  5. v-model:content="content"
  6. theme="snow"
  7. content-type="html"
  8. :placeholder="placeholder"
  9. :toolbar="toolbar"
  10. @update:content="contentChange"
  11. />
  12. </div>
  13. </template>
  14. <script setup lang="ts">
  15. import { ref, watch } from 'vue';
  16. import { QuillEditor } from '@vueup/vue-quill';
  17. import '@vueup/vue-quill/dist/vue-quill.snow.css';
  18. // import ImageResize from 'quill-image-resize-module';
  19. defineOptions({
  20. name: 'RichEditor',
  21. });
  22. const props = withDefaults(
  23. defineProps<{
  24. modelValue: string | null;
  25. placeholder?: string;
  26. }>(),
  27. {
  28. placeholder: '请输入',
  29. }
  30. );
  31. const emit = defineEmits(['update:modelValue', 'change']);
  32. const toolbar = [
  33. [
  34. 'bold',
  35. 'italic',
  36. 'underline',
  37. 'strike',
  38. 'link',
  39. 'image',
  40. { script: 'sub' },
  41. { script: 'super' },
  42. { align: [] },
  43. { indent: '-1' },
  44. { indent: '+1' },
  45. ],
  46. [{ header: [1, 2, 3, 4, 5, 6, false] }],
  47. [{ size: ['small', false, 'large', 'huge'] }],
  48. ['clean'],
  49. ];
  50. // const modules = {
  51. // name: 'imageResize',
  52. // module: ImageResize,
  53. // options: {
  54. // modules: ['Resize'],
  55. // },
  56. // };
  57. const editorRef = ref();
  58. const content = ref<string>('');
  59. function contentChange() {
  60. emit('update:modelValue', content);
  61. emit('change', content);
  62. }
  63. watch(
  64. () => props.modelValue,
  65. (val) => {
  66. content.value = val || '';
  67. },
  68. {
  69. immediate: true,
  70. }
  71. );
  72. </script>
  73. <style>
  74. .rich-editor .ql-container {
  75. height: 300px;
  76. }
  77. .rich-editor em {
  78. font-style: italic;
  79. }
  80. </style>