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

第一步

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.mfbz.cn/a/560225.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【C语言__结构体__复习篇5】

目录 前言 一、结构体基础知识 1.1 结构体的语法形式 1.2 创建结构体变量 1.3 结构体变量的初始化 1.4 点(.)操作符和箭头(->)操作符 二、匿名结构体 三、结构体自引用 四、结构体内存对齐 4.1 内存对齐的规则 4.2 出现结构体内存对齐的原因 4.3 修改默认对齐数 五、结…

JavaScript高级

一、JavaScript 面向对象 面向对象编程介绍ES6 中的类和对象类的继承面向对象案例 1. 面向对象编程介绍 1.1 两大编程思想 面向过程面向对象 1.2 面向过程编程 POP(Process-oriented programming) 面向过程 就是分析出解决问题所需要的步骤&#xff0c;然后用函数把这些步…

shell脚本编程的例子(50例子)-1

前言 为了提高教学质量&#xff0c;并且能够让童鞋们更好的理解和运用shell脚本以及相关编程&#xff0c;特编写了50个shell例子&#xff0c;目前还在整理过程ing&#xff0c;计划分三期完成。请有需要的同学收藏。后续会申请VIP阅读。…… ^.^ …… ^…^ 实验环境&#xff1…

javaWeb项目-智慧餐厅点餐管理系统功能介绍

项目关键技术 开发工具&#xff1a;IDEA 、Eclipse 编程语言: Java 数据库: MySQL5.7 框架&#xff1a;ssm、Springboot 前端&#xff1a;Vue、ElementUI 关键技术&#xff1a;springboot、SSM、vue、MYSQL、MAVEN 数据库工具&#xff1a;Navicat、SQLyog 1、JavaScript Java…

C语言进阶课程学习记录-内存操作经典问题分析

C语言进阶课程学习记录-内存操作经典问题分析 实验-示例1优化 实验-示例2优化 实验-示例3实验-示例4小结 本文学习自狄泰软件学院 唐佐林老师的 C语言进阶课程&#xff0c;图片全部来源于课程PPT&#xff0c;仅用于个人学习记录 实验-示例1 #include <stdio.h> #include…

ChatGPT研究论文提示词集合1-【主题选择与问题研究、文献综述】

点击下方▼▼▼▼链接直达AIPaperPass &#xff01; AIPaperPass - AI论文写作指导平台 目录 1.主题选择与问题定义 2.文献综述 3.书籍介绍 AIPaperPass智能论文写作平台 近期小编按照学术论文的流程&#xff0c;精心准备一套学术研究各个流程的提示词集合。总共14个步骤…

HTTP请求中的cookie与session(servlet实现登录页面的表单验证)

一、cookie 与 session 1&#xff09;cookie 与 session 的定义 2&#xff09;相关的servlet中的 方法 二、代码实现 登录页面 1&#xff09;先用 vscode 编写登录页面 注意文件的路径 在webapp路径下 <!DOCTYPE html> <html lang"en"><head>&…

ai写作强大,ai写作哪个软件最好用?

在当今数字化时代&#xff0c;ai技术的发展正以惊人的速度改变着我们的生活和工作方式。其中&#xff0c;ai写作作为一项令人瞩目的创新&#xff0c;展示了强大的文本生成能力。然而&#xff0c;随着各种ai写作软件的涌现&#xff0c;人们不禁困惑&#xff1a;哪个软件才是最好…

【网络设备巡检命令】--思科、华为、H3C、锐捷

【网络设备巡检命令】--思科、华为、H3C、锐捷 一、思科二、华为三、H3C四、锐捷 &#x1f496;The Begin&#x1f496;点点关注&#xff0c;收藏不迷路&#x1f496; 一、思科 1、查看系统信息&#xff1a; show version2、查看时间&#xff1a; show clock3、查看序列号&a…

Zed 捕获图像+测距

Zed 捕获图像测距 1. 导入相关库2. 相机初始化设置3. 获取中心点深度数据4. 计算中心点深度值5. 完整代码5. 实验效果 此代码基于官方代码基础上进行改写&#xff0c;主要是获取zed相机深度画面中心点的深度值&#xff0c;为yolo测距打基础。 1. 导入相关库 import pyzed.sl …

C语言 ─── 操作符详解

目录 1. 算术操作符 2. 移位操作符 2.1 左移操作符 2.2 右移操作符 3. 位操作符 4. 复合赋值符 5. 单目操作符 6. 逗号表达式 7. 隐式类型转换 7.1 整型提升的意义&#xff1a; 7.2 如何进行整体提升呢&#xff1f; 8. 算术转换 ★★★数组名 1. 算术操作符 -…

redis与etcd的对比

1.redis是一种高级的key&#xff1a;value存储系统&#xff0c;其中value支持五种数据类型&#xff1a; 1.1 字符串&#xff08;strings&#xff09; 1.2 字符串列表&#xff08;lists&#xff09; 1.3 字符串集合&#xff08;sets&#xff09; 1.4 有序字符串集合&#xff08;…

管理 nodejs 版本工具 nvm

nvm 方便切换不同版本的 node 及 对应的 npm 版本 一、安装nvm nvm官网 &#xff08;内含下载的文件&#xff0c;点击进去下载&#xff0c;并按照 网站文档步骤 操作即可&#xff09; 二、nvm 基础命令 nvm arch&#xff1a;显示node是运行在32位还是64位。nvm install <…

centos修改启动项加载不同内核

一.背景&#xff1a; 虚拟机中有时需要编译好几个内核版本&#xff0c;make install后系统存在几个内核版本。需要再哪个内核上开发调试就启动特定的内核版本。这就需要修改启动时的内核版本&#xff0c;再物理机或虚拟机启动时可以上下键选择。但有时是docket云环境中或远程时…

CANoe中LIN工程主节点的配置(如何切换调度表)

1&#xff1a;前置条件 1&#xff09;工程已经建立&#xff0c;simulation窗口已经配置好&#xff08;包括且不限于通道mappin好&#xff0c;数据库文件已经添加&#xff09; 2&#xff09;我已系统自带sampleCfg工程&#xff0c;作为例子。如下图 2 &#xff1a;主节点的配置…

前端css中table表格的属性使用

前端css中table表格的属性使用 一、前言二、常见的表格属性1.边框的样式2.布局和对齐3.间距和填充4.背景和颜色5.字体的样式6.边框的圆角 三、简单的表格&#xff0c;例子11.源码12.源码1效果截图 四、给表格添加动画效果&#xff0c;例子21.源码22.源码2的运行效果 五、结语六…

【热门话题】探索与心得:深入体验Microsoft Edge浏览器

&#x1f308;个人主页: 鑫宝Code &#x1f525;热门专栏: 闲话杂谈&#xff5c; 炫酷HTML | JavaScript基础 ​&#x1f4ab;个人格言: "如无必要&#xff0c;勿增实体" 文章目录 探索与心得&#xff1a;深入体验Microsoft Edge浏览器一、Edge浏览器概述1.1 发…

通快霍廷格TruPlasma MF中频电源培训PPT课件内容下图

通快霍廷格TruPlasma MF中频电源培训PPT课件内容下图

美业连锁门店收银系统源码-如何查看收款门店对应的加盟商?

美业管理系统源码 博弈美业SaaS系统 连锁多门店美业收银系统源码 多门店管理 / 会员管理 / 预约管理 / 排班管理 / 商品管理 / 促销活动 PC管理后台、手机APP、iPad APP、微信小程序 第一步&#xff1a; 登录pc管理后端 第二步&#xff1a; 进入企业组织管理-门店管理&a…

【Linux】认识文件(一):文件标识符

【Linux】认识文件&#xff08;一&#xff09;&#xff1a;文件标识符 一.什么是文件&#xff1f;1.文件的本质2.文件的分类 二.访问文件操作1.C语言中的访问文件接口i.fopenii.fcloseiii.fwrite 2.系统访问文件接口i.openii.closeiii.write 三.文件管理1.对所有打开文件的管理…