normalArea.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <template>
  2. <div>
  3. <article :id="id">
  4. <editor v-model="inputValue" :class="'tinymce_'+id" :init="init" @input="changeText" />
  5. </article>
  6. </div>
  7. </template>
  8. <script>
  9. import tinymce from 'tinymce/tinymce'
  10. import Editor from '@tinymce/tinymce-vue'
  11. import 'tinymce/themes/silver/theme'
  12. import 'tinymce/icons/default/icons'
  13. export default {
  14. components: {
  15. Editor
  16. },
  17. props: {
  18. id: {
  19. type: String,
  20. default: '',
  21. required: true
  22. },
  23. value: {
  24. type: String,
  25. default: '',
  26. required: false
  27. },
  28. height: {
  29. type: Number,
  30. default: 200,
  31. required: false
  32. }
  33. },
  34. data() {
  35. return {
  36. inputValue: '',
  37. edit: false,
  38. init: {
  39. auto_focus: true,
  40. language_url: '/tinymce/langs/zh_CN.js',
  41. language: 'zh_CN',
  42. skin_url: '/tinymce/skins/ui/oxide', // 编辑器需要一个skin才能正常工作,所以要设置一个skin_url指向之前复制出来的skin文件
  43. height: this.height,
  44. browser_spellcheck: true, // 拼写检查
  45. branding: false, // 去水印
  46. elementpath: false, // 禁用编辑器底部的状态栏
  47. statusbar: false, // 隐藏编辑器底部的状态栏
  48. paste_data_images: true, // 允许粘贴图像
  49. menubar: false, // 隐藏最上方menu
  50. fontsize_formats: '14px 16px 18px 20px 24px 26px 28px 30px 32px 36px', // 字体大小
  51. file_picker_types: 'image',
  52. images_upload_credentials: true,
  53. plugins: 'lists table textcolor wordcount contextmenu', // 引入插件
  54. toolbar: 'bold italic underline strikethrough | fontsizeselect | forecolor backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent table | undo redo | removeformat formatselect'
  55. }
  56. }
  57. },
  58. watch: {
  59. value: {
  60. handler(newV, oldV) {
  61. console.log(newV)
  62. this.inputValue = newV
  63. },
  64. immediate: true
  65. }
  66. },
  67. mounted() {
  68. tinymce.init({ selector: `.tinymce_${this.id}` })
  69. },
  70. methods: {
  71. changeText(e) { // 富文本内容改变
  72. this.inputValue = e
  73. this.$emit('update:value', this.inputValue)
  74. this.$emit('change', this.inputValue)
  75. }
  76. }
  77. }
  78. </script>