在Vue项目使用kindEditor富文本编译器以及上传图片

news2024/10/7 8:31:29

第一步

npm install kindeditor

第二步,建立kindeditor.vue组件

<template>
  <div class="kindeditor">
    <textarea :id="id" name="content" v-model="outContent"></textarea>
  </div>
</template>

<script>
  import '../../node_modules/kindeditor/kindeditor-all.js'
  // import '../utils/kindeditor-all.js?v=1'
  import '../../node_modules/kindeditor/lang/zh-CN.js'
  import '../../node_modules/kindeditor/themes/default/default.css'

  export default {
    name: 'kindeditor',
    data() {
      return {
        editor: null,
        outContent: this.content
      }
    },
    props: {
      content: {
        type: String,
        default: ''
      },
      id: {
        type: String,
        required: true
      },
      width: {
        type: String
      },
      height: {
        type: String
      },
      minWidth: {
        type: Number,
        default: 650
      },
      minHeight: {
        type: Number,
        default: 100
      },
      items: {
        type: Array,
        default: function () {
          // lineheight  行距自定了,可全局搜索   ‘自定义行距’ 在/utils/kindeditor-all.js文件裏
          return [
            'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
            'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
            'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
            'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
            'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
            'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image', 'multiimage',
            'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
            'anchor', 'link', 'unlink', '|', 'about'
          ]
        }
      },
      noDisableItems: {
        type: Array,
        default: function () {
          return ['source', 'fullscreen']
        }
      },
      filterMode: {
        type: Boolean,
        default: true
      },
      htmlTags: {
        type: Object,
        default: function () {
          return {
            font: ['color', 'size', 'face', '.background-color'],
            span: ['style'],
            div: ['class', 'align', 'style'],
            table: ['class', 'border', 'cellspacing', 'cellpadding', 'width', 'height', 'align', 'style'],
            'td,th': ['class', 'align', 'valign', 'width', 'height', 'colspan', 'rowspan', 'bgcolor', 'style'],
            a: ['class', 'href', 'target', 'name', 'style'],
            embed: ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality',
              'style', 'align', 'allowscriptaccess', '/'
            ],
            img: ['src', 'width', 'height', 'border', 'alt', 'title', 'align', 'style', '/'],
            hr: ['class', '/'],
            br: ['/'],
            'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6': ['align', 'style'],
            'tbody,tr,strong,b,sub,sup,em,i,u,strike': []
          }
        }
      },
      wellFormatMode: {
        type: Boolean,
        default: true
      },
      resizeType: {
        type: Number,
        default: 2
      },
      themeType: {
        type: String,
        default: 'default'
      },
      langType: {
        type: String,
        default: 'zh-CN'
      },
      designMode: {
        type: Boolean,
        default: true
      },
      fullscreenMode: {
        type: Boolean,
        default: false
      },
      basePath: {
        type: String
      },
      themesPath: {
        type: String
      },
      pluginsPath: {
        type: String,
        default: ''
      },
      langPath: {
        type: String
      },
      minChangeSize: {
        type: Number,
        default: 5
      },
      loadStyleMode: {
        type: Boolean,
        default: true
      },
      urlType: {
        type: String,
        default: ''
      },
      newlineTag: {
        type: String,
        default: 'p'
      },
      pasteType: {
        type: Number,
        default: 2
      },
      dialogAlignType: {
        type: String,
        default: 'page'
      },
      shadowMode: {
        type: Boolean,
        default: true
      },
      zIndex: {
        type: Number,
        default: 811213
      },
      useContextmenu: {
        type: Boolean,
        default: true
      },
      syncType: {
        type: String,
        default: 'form'
      },
      indentChar: {
        type: String,
        default: '\t'
      },
      cssPath: {
        type: [String, Array]
      },
      cssData: {
        type: String
      },
      bodyClass: {
        type: String,
        default: 'ke-content'
      },
      colorTable: {
        type: Array
      },
      afterCreate: {
        type: Function
      },
      afterChange: {
        type: Function
      },
      afterTab: {
        type: Function
      },
      afterFocus: {
        type: Function
      },
      afterBlur: {
        type: Function
      },
      afterUpload: {
        type: Function
      },
      uploadJson: {
        type: String
      },
      fileManagerJson: {
        type: Function
      },
      allowPreviewEmoticons: {
        type: Boolean,
        default: true
      },
      allowImageUpload: {
        type: Boolean,
        default: true
      },
      allowFlashUpload: {
        type: Boolean,
        default: true
      },
      allowMediaUpload: {
        type: Boolean,
        default: true
      },
      allowFileUpload: {
        type: Boolean,
        default: true
      },
      allowFileManager: {
        type: Boolean,
        default: false
      },
      fontSizeTable: {
        type: Array,
        default: function () {
          return ['9px', '10px', '12px', '14px', '16px', '18px', '24px', '32px']
        }
      },
      imageTabIndex: {
        type: Number,
        default: 0
      },
      formatUploadUrl: {
        type: Boolean,
        default: true
      },
      fullscreenShortcut: {
        type: Boolean,
        default: false
      },
      extraFileUploadParams: {
        type: Array,
        default: function () {
          return []
        }
      },
      filePostName: {
        type: String,
        default: 'imgFile'
      },
      fillDescAfterUploadImage: {
        type: Boolean,
        default: false
      },
      afterSelectFile: {
        type: Function
      },
      pagebreakHtml: {
        type: String,
        default: '<hr style=”page-break-after: always;” class=”ke-pagebreak” />'
      },
      allowImageRemote: {
        type: Boolean,
        default: true
      },
      autoHeightMode: {
        type: Boolean,
        default: false
      },
      fixToolBar: {
        type: Boolean,
        default: false
      },
      tabIndex: {
        type: Number
      }
    },
    watch: {
      content(val) {
        this.editor && val !== this.outContent && this.editor.html(val)
      },
      outContent(val) {
        this.$emit('update:content', val)
        this.$emit('on-content-change', val)
      }
    },
    created(){

    },
    mounted() {
      var _this = this
      _this.editor = window.KindEditor.create('#' + this.id, {
        width: _this.width,
        height: _this.height,
        minWidth: _this.minWidth,
        minHeight: _this.minHeight,
        items: _this.items,
        noDisableItems: _this.noDisableItems,
        filterMode: _this.filterMode,
        htmlTags: _this.htmlTags,
        wellFormatMode: _this.wellFormatMode,
        resizeType: _this.resizeType,
        themeType: _this.themeType,
        langType: _this.langType,
        designMode: _this.designMode,
        fullscreenMode: _this.fullscreenMode,
        basePath: _this.basePath,
        themesPath: _this.cssPath,
        pluginsPath: _this.pluginsPath,
        langPath: _this.langPath,
        minChangeSize: _this.minChangeSize,
        loadStyleMode: _this.loadStyleMode,
        urlType: _this.urlType,
        newlineTag: _this.newlineTag,
        pasteType: _this.pasteType,
        dialogAlignType: _this.dialogAlignType,
        shadowMode: _this.shadowMode,
        zIndex: _this.zIndex,
        useContextmenu: _this.useContextmenu,
        syncType: _this.syncType,
        indentChar: _this.indentChar,
        cssPath: _this.cssPath,
        cssData: _this.cssData,
        bodyClass: _this.bodyClass,
        colorTable: _this.colorTable,
        afterCreate: _this.afterCreate,
        afterChange: function () {
          _this.afterChange
          _this.outContent = this.html()
        },
        afterTab: _this.afterTab,
        afterFocus: _this.afterFocus,
        afterBlur: _this.afterBlur,
        afterUpload: _this.afterUpload,
        uploadJson: _this.uploadJson,
        fileManagerJson: _this.fileManagerJson,
        allowPreviewEmoticons: _this.allowPreviewEmoticons,
        allowImageUpload: _this.allowImageUpload,
        allowFlashUpload: _this.allowFlashUpload,
        allowMediaUpload: _this.allowMediaUpload,
        allowFileUpload: _this.allowFileUpload,
        allowFileManager: _this.allowFileManager,
        fontSizeTable: _this.fontSizeTable,
        imageTabIndex: _this.imageTabIndex,
        formatUploadUrl: _this.formatUploadUrl,
        fullscreenShortcut: _this.fullscreenShortcut,
        extraFileUploadParams: _this.extraFileUploadParams,
        filePostName: _this.filePostName,
        fillDescAfterUploadImage: _this.fillDescAfterUploadImage,
        afterSelectFile: _this.afterSelectFile,
        pagebreakHtml: _this.pagebreakHtml,
        allowImageRemote: _this.allowImageRemote,
        autoHeightMode: _this.autoHeightMode,
        fixToolBar: _this.fixToolBar,
        tabIndex: _this.tabIndex
      })
      



    } 
  }

</script>

<style>

</style>

第三步引入

<template>
 <div id="app">
  <editor id="editor_id" height="500px" width="700px" :content.sync="editorText"
   :afterChange="afterChange()"
   :loadStyleMode="false"
   :uploadJson="uploadJson"
   @on-content-change="onContentChange"></editor>
 <div> editorTextCopy: {{ editorTextCopy }} </div>

 </div>
</template>

<script>
import editor from './components/kindeditor.vue'

export default {
 name: 'app',
 components: {
 editor
 },
 data () {
 return {
 uploadJson:process.env.VUE_APP_BASE_API +'/resource/oss/uploadByNoToken', //上传图片的接口地址
  editorText: '直接初始化值', // 双向同步的变量
  editorTextCopy: '' // content-change 事件回掉改变的对象
 }
 },
 methods: {
 onContentChange (val) {
  this.editorTextCopy = val;
  window.console.log(this.editorTextCopy)
 },
 afterChange () {
 }
 }
}
</script>

如果需要自定义行距下拉菜单可以直接修改kindeditor-all.js这个。
在这里插入图片描述
上传图片filePostName默认值要改为自己接口需要接口的key
uploadJson要传入自己的接口地址
在这里插入图片描述
然后在kindeditor-all.js里找到这个方法

KindEditor.plugin('image', function(K) {})

在这里插入图片描述

afterUpload : function(data) {}  这个data是自己接口返回的数据var url = data.data.url;指向自己的url路径

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1610984.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

49-PCIE转网口电路设计

视频链接 PCIE转网口电路设计01_哔哩哔哩_bilibili PCIe转网口电路设计 1、PCIE转网口电路设计基本介绍 pcie转网口的设计&#xff0c;一般有intel (i350)和网讯&#xff08;wx1860&#xff09;两种方案。 2、PCIE转网口的方案 2.1、I350 2.2、WX1860 (网迅) 国产化&#…

【Java】如何获取客户端IP地址

在项目中往往涉及到“获取客户端IP地址”&#xff0c;常见到下面这样子的代码&#xff1a; package com.utils;import cn.hutool.core.util.StrUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.http.server.reactive.ServerHttpRequest; import java.net…

NotePad++联动ABAQUS

Abaqus 中脚本运行 1. 命令区kernel Command Line Interface &#xff08;KCLI&#xff09; execfile(C:\\temp\second develop\chapter2\pyTest1.py)2. CAE-Run Script File->Run Script 3. Abaqus command Abaqus cae noGUIscript.py(前后处理都可)Abaqus Python scr…

在PostgreSQL中如何有效地批量导入大量数据,并确保数据加载过程中的性能和稳定性?

文章目录 解决方案1. 使用COPY命令2. 调整配置参数3. 禁用索引和约束4. 使用事务5. 并发导入 总结 在PostgreSQL中&#xff0c;批量导入大量数据是一个常见的需求&#xff0c;特别是在数据迁移、数据仓库填充或大数据分析等场景中。为了确保数据加载过程中的性能和稳定性&#…

【Hadoop3.3.6全分布式环境搭建】

说明: 完成Hadoop全分布式环境搭建,需准备至少3台虚拟机(master slave01 slave02)环境: VMWare + Centos7 + JDK1.8+ Hadoop3.3.6主机规划: 主节点:master从节点:slave01 , slave02 一、准备工作 1、所有主机安装jdk 上传jdk-8u171-linux-x64.tar.gz到/root目录下,然后…

数组中两个字符串的最短距离---一题多解(贪心/二分)

点击跳转到题目 方法&#xff1a;贪心 / 二分 目录 贪心&#xff1a; 二分&#xff1a; 贪心&#xff1a; 要找出字符串数组中指定两个字符串的最小距离&#xff0c;即找出指定字符串对应下标之差的最小值 思考&#xff1a;如果是直接暴力求解&#xff0c;需要两层for循环…

浏览器跨标签页通信的方式都有哪些

跨标签页的实际应用场景&#xff1a; 1. 共享登录状态&#xff1a; 用户登录后&#xff0c;多个标签页中需要及时获取到登录状态&#xff0c;以保持一致的用户信息。这种情况&#xff0c;可以使用浏览器的 localStorage 或者 sessionStorage 来存储登录状态&#xff0c;并通过…

面试不慌张:一文读懂FactoryBean的实现原理

大家好&#xff0c;我是石头~ 在深入探讨Spring框架内部机制时&#xff0c;FactoryBean无疑是一个关键角色&#xff0c;也是面试中经常出现的熟悉面孔。 不同于普通Java Bean&#xff0c;FactoryBean是一种特殊的Bean类型&#xff0c;它的存在并非为了提供业务逻辑&#xff0c;…

串口小项目 - 声控刷抖音

项目准备&#xff1a; orangepi02 语言 模块: SU-03T 电脑 接线: 语言模块 - orangepi VCC - 5V GND - GND B7(RX)--RX-5 orangepi 手机 通过usb 连接 实现思路图: 语言模块接收到语言信息&#xff0c;发送到 H616 去处理&#xff0c;H616再控制手机实现语言刷抖音的功能 …

(2022级)成都工业学院数据库原理及应用实验八: 数据库恢复技术

写在前面 1、基于2022级软件工程/计算机科学与技术实验指导书 2、成品仅提供参考 3、如果成品不满足你的要求&#xff0c;请寻求其他的途径 运行环境 window11家庭版 Navicat Premium 16 Mysql 8.0.36 实验要求 1、使用mysqldump实现数据库备份。 2、使用mysqldump实…

LCR 023. 相交链表

给定两个单链表的头节点 headA 和 headB &#xff0c;请找出并返回两个单链表相交的起始节点。如果两个链表没有交点&#xff0c;返回 null 。 图示两个链表在节点 c1 开始相交&#xff1a; 题目数据 保证 整个链式结构中不存在环。 注意&#xff0c;函数返回结果后&#xf…

【HTML】H5新增元素记录

H5 新增元素特性 1. 语义化标签 语义化标签的好处&#xff1a; 对于浏览器来说&#xff0c;标签不够语义化对于搜索引擎来说&#xff0c;不利于SEO的优化 语义化标签&#xff1a; header:头部元素nav&#xff1a;导航section:定义文档某个区域的元素article:内容元素aside…

文心一言 VS 讯飞星火 VS chatgpt (241)-- 算法导论17.3 7题

七、为动态整数多重集 S (允许包含重复值)设计一种数据结构&#xff0c;支持如下两个操作&#xff1a;① INSERT(S,x) 将 x 插入 S 中&#xff1b;② DELETE-LARGER-HALF(S) 将最大的 ⌈|S|/2⌉ 个元素从S中删除。解释如何实现这种数据结构&#xff0c;使得任意 m 个 INSERT 和…

linux-centos虚拟机设置固定ip

环境准备 虚拟机版本&#xff1a;centos7 安装环境&#xff1a;vmware17 1、设置网络连接 虚拟机-设置-网络适配器-NAT模式 2、查看子网信息 编辑-虚拟网络编辑器-NAT模式-NAT设置 查看子网ip和网关ip 下一步要用 3、修改配置文件 vim /etc/sysconfig/network-scripts…

企业上云数字化转型的关键——选对服务器虚拟化

盘点市面上的主流虚拟化软件 虚拟化技术就像可以随意组合的乐高积木&#xff0c;可以高效、灵活地利用计算资源。世面上主流虚拟化很多&#xff0c;各有长处和短板。今天先来盘点一下市面上的主流虚拟化软件&#xff0c;一探究竟。 虚拟化的老牌巨头——VMware 老牌虚拟化巨…

Java数据结构-堆和优先级队列

目录 1. 相关概念2. PriorityQueue的实现2.0 搭建整体框架2.1 堆的创建和调整2.2 插入元素2.3 出堆顶元素 3. 全部代码&#xff08;包含大根堆和小根堆&#xff09;4. PriorityQueue的使用5. Top-K问题 之前我们学习的二叉树的存储方式是链式存储&#xff0c;&#xff08;不清楚…

VLOOKUP函数使用,为什么会报错“引用有问题”?

VLOOKUP函数的使用非常广泛&#xff0c;在excel2007版之后的软件中&#xff0c;使用VLOOKUP函数也许会遇到这样的场景&#xff0c;明明公式是没有问题的&#xff0c;公式还会报错“引用有问题”。 一、报错场景 输入公式后&#xff0c;回车确认&#xff0c;显示如下报错&…

嵌入式学习57-ARM7(字符设备驱动框架led)

知识零碎&#xff1a; kernel 内核 printk 内核打印 cat /proc/devices mknod ? 查看指令 gcc -oapp hello.c 字符设备驱动流程 字符设备程序运行流程 gcc中-c和-o是编译时可选的参数 -c …

揭阳硕榕超市管理系统的设计与实现(论文)_kaic

摘 要 在互联网高速发展环境下&#xff0c;传统的管理手段无法满足对信息的高效、快速的管理要求。为顺应时代发展的需要&#xff0c;提高超市的管理效能&#xff0c;提高超市的管理速度&#xff0c;构建一个信息化的工作流程&#xff0c;揭阳硕榕超市管理系统应运而生。 根…

Jmeter04:关联

1 Jmeter组件&#xff1a;关联 概括&#xff1a;2个请求之间不是独立的&#xff0c;一个请求响应的结果是作为另一个请求提交的数据&#xff0c;存在数据交互 1.1 是什么&#xff1f; 就是一个请求的结果是另一个请求提交的数据&#xff0c;二者不再是独立 1.2 为什么&#x…