index.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <div class="home">
  3. <div :id="domId">
  4. <!-- <p v-html="centert"></p> -->
  5. </div>
  6. </div>
  7. </template>
  8. <script>
  9. // 引入 wangEditor
  10. import wangEditor from '../../../static/wangeditor'
  11. export default {
  12. props: ['domId', 'height', 'width', 'centert'], // 定义当前需要渲染上的dom节点的Id
  13. data() {
  14. return {
  15. editor: null,
  16. domData: this.domId,
  17. showCentent: true
  18. // editorData: ''
  19. }
  20. },
  21. mounted() {
  22. // eslint-disable-next-line no-undef
  23. const editor = new wangEditor(`#${this.domData}`)
  24. // 配置 onchange 回调函数,将数据同步到 vue 中
  25. editor.config.onchange = (newHtml) => {
  26. this.$emit('func', newHtml)
  27. }
  28. editor.config.menus = [
  29. // 菜单配置
  30. 'head', // 标题
  31. 'bold', // 粗体
  32. 'fontSize', // 字号
  33. 'fontName', // 字体
  34. 'italic', // 斜体
  35. 'underline', // 下划线
  36. 'strikeThrough', // 删除线
  37. 'foreColor', // 文字颜色
  38. 'backColor', // 背景颜色
  39. 'link', // 插入链接
  40. 'list', // 列表
  41. 'justify', // 对齐方式
  42. 'quote', // 引用
  43. 'emoticon', // 表情
  44. 'image', // 插入图片
  45. 'table', // 表格
  46. 'code', // 插入代码
  47. 'undo', // 撤销
  48. 'redo' // 重复
  49. ]
  50. // 创建编辑器
  51. this.editor = editor
  52. },
  53. beforeDestroy() {
  54. // 调用销毁 API 对当前编辑器实例进行销毁
  55. this.editor.destroy()
  56. this.editor = null
  57. },
  58. methods: {
  59. getEditorData() {
  60. // 通过代码获取编辑器内容
  61. const data = this.editor.txt.html()
  62. alert(data)
  63. }
  64. }
  65. }
  66. </script>
  67. <style lang="less">
  68. @height: 156px;
  69. .home {
  70. /*width: 65%;*/
  71. margin: auto;
  72. position: relative;
  73. height: 198px;
  74. }
  75. .w-e-text-container{
  76. height: @height !important;/*!important是重点,因为原div是行内样式设置的高度300px*/
  77. }
  78. /*.w-e-text-container{*/
  79. /* height: 700px !important;!*!important是重点,因为原div是行内样式设置的高度300px*!*/
  80. /*}*/
  81. </style>