BlockNoteEditor.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <template>
  2. <ReactWrapper
  3. component="BlockNoteReact"
  4. :props="editorProps"
  5. key="blocknote-editor"
  6. class="blocknote-container"
  7. />
  8. </template>
  9. <script setup>
  10. import { ref, watch } from 'vue';
  11. import { createReactWrapper } from 'vue-react-wrapper';
  12. import BlockNoteReact from './react-components/BlockNoteReact';
  13. const props = defineProps({
  14. modelValue: {
  15. type: [Array, Object, null],
  16. default: null
  17. },
  18. editable: {
  19. type: Boolean,
  20. default: true
  21. }
  22. });
  23. const emit = defineEmits(['update:modelValue','getHtml']);
  24. // 创建响应式props对象
  25. const editorProps = ref({
  26. modelValue: props.modelValue,
  27. onUpdateModelValue: (value,html) => {
  28. console.log('onUpdateModelValue', value,html);
  29. emit('update:modelValue', value);
  30. emit('getHtml', html);
  31. },
  32. editable: props.editable
  33. });
  34. const ReactWrapper = createReactWrapper(BlockNoteReact,editorProps)
  35. // 监听modelValue变化
  36. watch(() => props.modelValue, (newVal) => {
  37. editorProps.value.modelValue = newVal;
  38. }, { deep: true });
  39. </script>
  40. <style scoped>
  41. .blocknote-container {
  42. border: 1px solid #e5e7eb;
  43. border-radius: 6px;
  44. padding: 12px;
  45. min-height: 250px;
  46. margin: 16px 0;
  47. }
  48. :deep(.blocknote-editor) {
  49. font-size: 16px;
  50. line-height: 1.6;
  51. }
  52. :deep(.blocknote-toolbar) {
  53. border-bottom: 1px solid #f3f4f6;
  54. padding-bottom: 8px;
  55. }
  56. </style>