TextEdit.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <div class="text-edit-wrap">
  3. <div style="font-size:16px;margin-bottom:20px">文本编辑</div>
  4. <froala
  5. id="froala-editor"
  6. ref="froalaEditor"
  7. :tag="'textarea'"
  8. :config="froalaConfig"
  9. v-model="html"
  10. />
  11. </div>
  12. </template>
  13. <script>
  14. import VueFroala from 'vue-froala-wysiwyg';
  15. export default {
  16. name:'TextEdit',
  17. props:{
  18. content:''
  19. },
  20. data() {
  21. const that = this;
  22. return {
  23. html:this.content||'',
  24. editor: null,
  25. lastEditRange: null,
  26. froalaConfig:{
  27. toolbarButtons: [
  28. "textColor",
  29. "bold",
  30. "italic",
  31. "underline",
  32. "strikeThrough",
  33. "subscript",
  34. "superscript",
  35. "fontFamily",
  36. "fontSize",
  37. "color",
  38. "inlineClass",
  39. "inlineStyle",
  40. "paragraphStyle",
  41. "lineHeight",
  42. "paragraphFormat",
  43. "align",
  44. "formatOL",
  45. "formatUL",
  46. "outdent",
  47. "indent",
  48. "quote",
  49. "specialCharacters",
  50. "insertHR",
  51. "selectAll",
  52. "clearFormatting",
  53. "html",
  54. "undo",
  55. "redo",
  56. ],
  57. height: 800,
  58. fontSize: ["12", "14", "16", "18", "20", "24", "28", "32", "36", "40"],
  59. fontSizeDefaultSelection: "16",
  60. theme: "dark", //主题
  61. placeholderText: "请输入内容",
  62. language: "zh_cn", //国际化
  63. imageDefaultWidth: false,
  64. quickInsertEnabled: false,
  65. toolbarVisibleWithoutSelection: true, //是否开启 不选中模式
  66. toolbarSticky: false, //操作栏是否自动吸顶
  67. saveInterval: 0,
  68. events: {
  69. //this.editor 定义在vue data 中
  70. initialized: function () {
  71. // this.editor = editor;
  72. that.editor = this;
  73. // that.editor.html.set(that.value);
  74. // that.setHtml()
  75. },
  76. keyup: function (e, editor) {
  77. //添加事件,在每次按键按下时,都记录一下最后停留位置
  78. that.$nextTick(function () {
  79. that.lastEditRange = getSelection().getRangeAt(0);
  80. });
  81. },
  82. click: function (e, editor) {
  83. //添加事件,在每次鼠标点击时,都记录一下最后停留位置
  84. that.$nextTick(function () {
  85. that.lastEditRange = getSelection().getRangeAt(0);
  86. });
  87. },
  88. //内容改变事件
  89. contentChanged: function () {
  90. that.lastEditRange = getSelection().getRangeAt(0) || 0;
  91. // that.$emit('textChange', that.html)
  92. that.sendHtml()
  93. },
  94. },
  95. }
  96. }
  97. },
  98. methods: {
  99. sendHtml(){
  100. const str=this.html.replace(/<p data-f-id=\"pbf\".*?<\/p>/g, "")
  101. this.$emit('textChange', str)
  102. }
  103. },
  104. components:{}
  105. }
  106. </script>
  107. <style>
  108. </style>