index.vue 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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: '350',
  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. 'table',
  35. ]]
  36. // scaleEnabled: true,
  37. })
  38. //编辑器准备就绪后会触发该事件
  39. this.ue.addListener('ready', () => {
  40. //设置可以编辑
  41. this.ue.setEnabled()
  42. this.ue.setContent(this.r_content)
  43. })
  44. //编辑器内容修改时
  45. this.selectionchange()
  46. },
  47. //编辑器内容修改时
  48. selectionchange() {
  49. this.ue.addListener('selectionchange', () => {
  50. this.content = this.ue.getContent()
  51. })
  52. }
  53. },
  54. activated() {
  55. //初始化编辑器
  56. this.initEditor()
  57. },
  58. deactivated() {
  59. //销毁编辑器实例,使用textarea代替
  60. this.ue.destroy()
  61. //重置编辑器,可用来做多个tab使用同一个编辑器实例
  62. //this.ue.reset()
  63. //如果要使用同一个实例,请注释destroy()方法
  64. },
  65. computed: {
  66. // 利用计算属性返回prop里传过来的内容
  67. revecive: function() {
  68. return this.r_content
  69. }
  70. },
  71. watch: {
  72. // !!! 这里需要注意,需要一个watch来实时更新编辑器的内容
  73. revecive: function() {
  74. this.ue.setContent(this.r_content)
  75. }
  76. }
  77. }
  78. </script>
  79. <style>
  80. .edui-editor {
  81. z-index: 60 !important;
  82. }
  83. #edui_fixedlayer{
  84. z-index: 5000 !important;
  85. }
  86. </style>