index.vue 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <div>
  3. <div :id="this.id"></div>
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. name: 'Editor',
  9. props: ['id', 'r_content'],
  10. data() {
  11. return {
  12. ue: '', //ueditor实例
  13. content: '' //编辑器内容
  14. }
  15. },
  16. methods: {
  17. //初始化编辑器
  18. initEditor() {
  19. this.ue = UE.getEditor(this.id, {
  20. initialFrameWidth: '100%',
  21. initialFrameHeight: '600',
  22. topOffset: '110',
  23. toolbars: [[
  24. 'bold', //加粗
  25. 'underline', //下划线
  26. 'justifyleft', //居左对齐
  27. 'justifycenter', //居中对齐
  28. 'justifyright', //居右对齐
  29. 'justifyjustify', //两端对齐
  30. 'formatmatch', //格式刷
  31. 'fontsize', //字体大小
  32. 'fontfamily', //字体
  33. 'forecolor', //字体颜色
  34. 'insertrow',//前插入行
  35. 'inserttable', //插入表格
  36. 'edittable', //表格属性
  37. 'edittd', //单元格属性
  38. 'mergeright', //右合并单元格
  39. 'mergedown', //下合并单元格
  40. 'deleterow', //删除行
  41. 'deletecol', //删除列
  42. 'splittorows', //拆分成行
  43. 'splittocols', //拆分成列
  44. 'splittocells', //完全拆分单元格
  45. 'deletecaption', //删除表格标题
  46. 'deletetable', //删除表格
  47. 'mergecells', //合并多个单元格
  48. ]]
  49. // scaleEnabled: true,
  50. })
  51. //编辑器准备就绪后会触发该事件
  52. this.ue.addListener('ready', () => {
  53. //设置可以编辑
  54. this.ue.setEnabled()
  55. this.ue.setContent(this.r_content)
  56. })
  57. //编辑器内容修改时
  58. this.selectionchange()
  59. },
  60. //编辑器内容修改时
  61. selectionchange() {
  62. this.ue.addListener('selectionchange', () => {
  63. this.content = this.ue.getContent()
  64. })
  65. }
  66. },
  67. activated() {
  68. //初始化编辑器
  69. this.initEditor()
  70. },
  71. deactivated() {
  72. //销毁编辑器实例,使用textarea代替
  73. this.ue.destroy()
  74. //重置编辑器,可用来做多个tab使用同一个编辑器实例
  75. //this.ue.reset()
  76. //如果要使用同一个实例,请注释destroy()方法
  77. },
  78. computed: {
  79. // 利用计算属性返回prop里传过来的内容
  80. revecive: function() {
  81. return this.r_content
  82. }
  83. },
  84. watch: {
  85. // !!! 这里需要注意,需要一个watch来实时更新编辑器的内容
  86. revecive: function() {
  87. this.ue.setContent(this.r_content)
  88. }
  89. }
  90. }
  91. </script>
  92. <style>
  93. .edui-editor {
  94. z-index: 60 !important;
  95. }
  96. #edui_fixedlayer{
  97. z-index: 5000 !important;
  98. }
  99. </style>