editor.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <template>
  2. <div style="position: relative">
  3. <div
  4. :class="{ text: true }"
  5. contenteditable
  6. ref="editor"
  7. v-html="rawText"
  8. @input="input"
  9. ></div>
  10. <div v-if="!rawText" class="defaultText" v-html="defaultSl + dfaultText"></div>
  11. </div>
  12. </template>
  13. <script>
  14. import '@wangeditor/editor/dist/css/style.css'; // 引入 css
  15. // import { ref, onMounted } from 'vue';
  16. import config from '@/config/index';
  17. export default {
  18. props: {
  19. rawText: {
  20. type: String,
  21. default: '',
  22. },
  23. },
  24. data() {
  25. return {
  26. dfaultText: config.base.default_text || '',
  27. defaultSl: '<p style="margin: 10px auto; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 16px; line-height: 34.2px; font-family: &quot;Microsoft Yahei&quot; color: rgb(51, 51, 51); background-color: rgb(255, 255, 255);"><span>(示例)</span></p>'
  28. };
  29. },
  30. beforeMount() {},
  31. methods: {
  32. input(e) {
  33. this.$emit('update:rawText', e.target.innerHTML || '');
  34. },
  35. },
  36. emits: ['update:rawText'],
  37. };
  38. </script>
  39. <style scoped>
  40. .selectSpan {
  41. border-bottom: 3px solid #fff;
  42. }
  43. .text {
  44. height: calc(100vh - 186px);
  45. overflow-y: auto;
  46. outline: none;
  47. padding: 1em;
  48. }
  49. .text img {
  50. margin: 0 auto;
  51. }
  52. .text p {
  53. text-indent: 2em;
  54. }
  55. .defaultText {
  56. color: #999;
  57. position: absolute;
  58. z-index: -1;
  59. padding: 1em;
  60. top: 0;
  61. }
  62. </style>