Vue3中使用tinymce

1、下载

npm i tinymce
npm i @tinymce/tinymce-vue
npm install @jsdawn/vue3-tinymce

2、在public新建tinymce文件

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

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

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

<template>
  <div class="tinymce-box">
    <vue3-tinymce v-model="state.content" :setting="state.setting" />
  </div>
</template>

<script setup>
import { defineProps, reactive, watch, defineEmits } from 'vue'
// 引入组件
import Vue3Tinymce from '@jsdawn/vue3-tinymce'
const props = defineProps({
  modelValue: {
    type: String,
  },
})
const emits = defineEmits(['update:modelValue', 'contentChange'])
const state = reactive({
  content: props.modelValue,
  setting: {
    height: 400,
    selector: '#textarea1',
    toolbar:
      '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 |',
    toolbar_mode: 'sliding',
    quickbars_selection_toolbar:
      'removeformat | bold italic underline strikethrough | fontsize forecolor backcolor',
    plugins:
      'link image media table lists fullscreen quickbars wordcount,anchor',
    font_size_formats: '12px 14px 16px 18px',
    link_default_target: '_blank',
    link_title: false,
    nonbreaking_force_tab: true,
    // 以中文简体为例
    language_url: '/tinymce/langs/zh_CN.js', //引入语言包文件
    language: 'zh_CN', //语言类型

    // 自定义 图片上传模式
    custom_images_upload: true,

    // 复用 图片上传 api 地址
    images_upload_url:
      '此处填上传图片地址',

    // 上传成功回调函数,return 图片地址。默认 response.location
    custom_images_upload_callback: res => {
      // console.log(res,1111)
      return res.data
    },

    // 上传 api 请求头
    custom_images_upload_header: {
      token: `${window.localStorage.getItem('VEA-TOKEN')}`,
    },

    // 上传 api 额外的参数。图片默认 file
    // custom_images_upload_param: { },
  },
})
watch(
  () => state.content,
  () => {
    emits('update:modelValue', state.content)
    emits('contentChange', state.content)
  },
  {
    immediate: true,
    deep: true,
  }
)

watch(
  () => props.modelValue,
  () => {
    state.content = props.modelValue
  },
  {
    immediate: true,
    deep: true,
  }
)
</script>
<style scoped lang="scss">
.tinymce-box {
  :deep(.tox-promotion) {
    display: none;
  }
  :deep(.tox-statusbar__branding) {
    display: none;
  }
}
</style>

4、使用

<!-- 富文本编辑器页面 -->
<template>
  <div>
    <fu-content></fu-content>
  </div>
</template>
<script setup>
// 引入富文本组件
import fuContent from '@/components/TinymceEditor/index.vue'
</script>

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

  • 13
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Vue3使用Tinymce富文本编辑器,你可以按照以下步骤进行操作: 1. 首先,确保你已经安装了TinymceTinymce-Vue的相关包。你可以通过运行以下命令来安装Tinymce-Vue版本3: ``` npm install --save @tinymce/tinymce-vue@^3 ``` 2. 在你的Vue组件,引入Tinymce-Vue组件: ```javascript import { Editor } from '@tinymce/tinymce-vue'; ``` 3. 在你的模板使用Tinymce-Vue组件: ```html <template> <div> <editor v-model="content" :init="editorConfig"></editor> </div> </template> ``` 4. 在你的Vue组件,定义Tinymce的配置项: ```javascript export default { data() { return { content: '', editorConfig: { // 在这里配置Tinymce的选项 } }; } } ``` 5. 根据你的需求,配置Tinymce的选项。你可以参考Tinymce的官方文档和文文档来了解所有可用的选项。你也可以参考Tinymce-Vue在GitHub上的项目来获取更多示例和用法。 请注意,Tinymce-Vue版本4支持Vue3.0,而不支持Vue2.0。如果你的项目是Vue2.0,你需要安装Tinymce-Vue版本3。 希望这些信息对你有帮助!如果你需要更多的参考文档,你可以访问Tinymce的官方网站和文文档,以及Tinymce-Vue在GitHub上的项目。 #### 引用[.reference_title] - *1* *2* *3* [在vue3.0项目使用tinymce富文本编辑器](https://blog.csdn.net/mrjimin/article/details/121648927)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值