src/components/tinymce/index.vue

src/components/tinymce/index.vue

这个代码块是一个基于 Vue.js 的组件,用于集成 TinyMCE 富文本编辑器。以下是对代码块中各个部分的解释:

<template> 部分

<template>
  <div :class="{ fullscreen: fullscreen }" class="tinymce-container">
    <textarea :id="id" class="tinymce-textarea"></textarea>
  </div>
</template>
  • 解释
    • 使用了一个 div 容器来包裹一个 textarea 元素。
    • div 的类名根据 fullscreen 状态动态绑定,如果 fullscreen 为真,则添加 fullscreen 类。
    • textarea 元素的 id 属性是动态生成的,确保每个实例都有唯一的 ID。

<script> 部分

import toolbar from './toolbar';
import plugins from './plugins';
import styles from './style';
import remoteLoad from '@/utils/remoteLoad';
const {
    TinymceCDN } = require('@/plugins/cdn');

export default {
   
  name: 'tinymce',
  props: {
   
    height: {
   
      type: [Number, String],
      default: '500'
    },
    resize: {
   
      type: Boolean,
      default: true
    },
    value: {
   
      type: String,
      default: ''
    }
  },
  data() {
   
    return {
   
      id: 'editor-' + +new Date() + ((Math.random() * 1000).toFixed(0) + ''),
      firstInit: false,
      errorStatus: false,
      fullscreen: false
    };
  },
  mounted() {
   
    this.init();
  },
  methods: {
   
    async init() {
   
      try {
   
        await remoteLoad(TinymceCDN);
        if (window.tinymce) {
   
          this.initTinymce();
        } else {
   
          this.$message.error('加载资源失败');
        }
      } catch (error) {
   
        console.log(error);
        this.$message.error(error);
      }
    },
    initTinymce() {
   
      const that = this
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

@阿猫阿狗~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值