当前位置:   article > 正文

Vue3中使用tinymce_vue3使用tinymce

vue3使用tinymce

1、下载

  1. npm i tinymce
  2. npm i @tinymce/tinymce-vue
  3. npm install @jsdawn/vue3-tinymce

2、在public新建tinymce文件

  1. tinymce文件里面放skins和语言包langs
  2. 1.在node_modules文件夹中找到tinymce下的skins复制到项目public文件夹中
  3. 2.langs是语言包,在tinymce官网中下载中文包(如下图),点击按钮下载全部语言包,解压放至tinymce文件夹

在tinymce官网中下载中文包,Language Packages | Trusted Rich Text Editor | TinyMCE

3、在项目components文件夹下封装组件TinymceEditor,把下面的代码放进去

  1. <template>
  2. <div class="tinymce-box">
  3. <vue3-tinymce v-model="state.content" :setting="state.setting" />
  4. </div>
  5. </template>
  6. <script setup>
  7. import { defineProps, reactive, watch, defineEmits } from 'vue'
  8. // 引入组件
  9. import Vue3Tinymce from '@jsdawn/vue3-tinymce'
  10. const props = defineProps({
  11. modelValue: {
  12. type: String,
  13. },
  14. })
  15. const emits = defineEmits(['update:modelValue', 'contentChange'])
  16. const state = reactive({
  17. content: props.modelValue,
  18. setting: {
  19. height: 400,
  20. selector: '#textarea1',
  21. toolbar:
  22. 'undo redo | fullscreen | blocks alignleft aligncenter alignright alignjustify | link unlink | numlist bullist | image media table | fontsize forecolor backcolor | bold italic underline strikethrough | indent outdent | superscript subscript | removeformat |',
  23. toolbar_mode: 'sliding',
  24. quickbars_selection_toolbar:
  25. 'removeformat | bold italic underline strikethrough | fontsize forecolor backcolor',
  26. plugins:
  27. 'link image media table lists fullscreen quickbars wordcount,anchor',
  28. font_size_formats: '12px 14px 16px 18px',
  29. link_default_target: '_blank',
  30. link_title: false,
  31. nonbreaking_force_tab: true,
  32. // 以中文简体为例
  33. language_url: '/tinymce/langs/zh_CN.js', //引入语言包文件
  34. language: 'zh_CN', //语言类型
  35. // 自定义 图片上传模式
  36. custom_images_upload: true,
  37. // 复用 图片上传 api 地址
  38. images_upload_url:
  39. '此处填上传图片地址',
  40. // 上传成功回调函数,return 图片地址。默认 response.location
  41. custom_images_upload_callback: res => {
  42. // console.log(res,1111)
  43. return res.data
  44. },
  45. // 上传 api 请求头
  46. custom_images_upload_header: {
  47. token: `${window.localStorage.getItem('VEA-TOKEN')}`,
  48. },
  49. // 上传 api 额外的参数。图片默认 file
  50. // custom_images_upload_param: { },
  51. },
  52. })
  53. watch(
  54. () => state.content,
  55. () => {
  56. emits('update:modelValue', state.content)
  57. emits('contentChange', state.content)
  58. },
  59. {
  60. immediate: true,
  61. deep: true,
  62. }
  63. )
  64. watch(
  65. () => props.modelValue,
  66. () => {
  67. state.content = props.modelValue
  68. },
  69. {
  70. immediate: true,
  71. deep: true,
  72. }
  73. )
  74. </script>
  75. <style scoped lang="scss">
  76. .tinymce-box {
  77. :deep(.tox-promotion) {
  78. display: none;
  79. }
  80. :deep(.tox-statusbar__branding) {
  81. display: none;
  82. }
  83. }
  84. </style>

4、使用

  1. <!-- 富文本编辑器页面 -->
  2. <template>
  3. <div>
  4. <fu-content></fu-content>
  5. </div>
  6. </template>
  7. <script setup>
  8. // 引入富文本组件
  9. import fuContent from '@/components/TinymceEditor/index.vue'
  10. </script>

注:使用elementplus组件库中的el-dialog组件和tinymce富文本时,el-dialog层级高会盖住了富文本不显示,可以改tinymce的css样式或者改用ant组件库

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/672436
推荐阅读
相关标签
  

闽ICP备14008679号