温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

kindeditor富文本编辑器怎么在vue项目中使用

发布时间:2020-12-19 16:54:12 阅读:541 作者:Leah 栏目:开发技术
Vue开发者专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

本篇文章为大家展示了kindeditor富文本编辑器怎么在vue项目中使用,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

第一步,下载依赖

yarn add 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 '../../node_modules/kindeditor/lang/zh-CN.js'
import '../../node_modules/kindeditor/themes/default/default.css'

export default {
 name'kindeditor',
 data () {
 return {
  editornull,
  outContentthis.content
 }
 },
 props: {
 content: {
  typeString,
  default''
 },
 id: {
  typeString,
  requiredtrue
 },
 width: {
  typeString
 },
 height: {
  typeString
 },
 minWidth: {
  typeNumber,
  default650
 },
 minHeight: {
  typeNumber,
  default100
 },
 items: {
  typeArray,
  defaultfunction () {
  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: {
  typeArray,
  defaultfunction () {
  return ['source''fullscreen']
  }
 },
 filterMode: {
  typeBoolean,
  defaulttrue
 },
 htmlTags: {
  typeObject,
  defaultfunction () {
  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,h2,h3,h4,h5,h6,h7': ['align''style'],
   'tbody,tr,strong,b,sub,sup,em,i,u,strike': []
  }
  }
 },
 wellFormatMode: {
  typeBoolean,
  defaulttrue
 },
 resizeType: {
  typeNumber,
  default2
 },
 themeType: {
  typeString,
  default'default'
 },
 langType: {
  typeString,
  default'zh-CN'
 },
 designMode: {
  typeBoolean,
  defaulttrue
 },
 fullscreenMode: {
  typeBoolean,
  defaultfalse
 },
 basePath: {
  typeString
 },
 themesPath: {
  typeString
 },
 pluginsPath: {
  typeString,
  default''
 },
 langPath: {
  typeString
 },
 minChangeSize: {
  typeNumber,
  default5
 },
 loadStyleMode: {
  typeBoolean,
  defaulttrue
 },
 urlType: {
  typeString,
  default''
 },
 newlineTag: {
  typeString,
  default'p'
 },
 pasteType: {
  typeNumber,
  default2
 },
 dialogAlignType: {
  typeString,
  default'page'
 },
 shadowMode: {
  typeBoolean,
  defaulttrue
 },
 zIndex: {
  typeNumber,
  default811213
 },
 useContextmenu: {
  typeBoolean,
  defaulttrue
 },
 syncType: {
  typeString,
  default'form'
 },
 indentChar: {
  typeString,
  default'\t'
 },
 cssPath: {
  type: [ StringArray ]
 },
 cssData: {
  typeString
 },
 bodyClass: {
  typeString,
  default'ke-content'
 },
 colorTable: {
  typeArray
 },
 afterCreate: {
  typeFunction
 },
 afterChange: {
  typeFunction
 },
 afterTab: {
  typeFunction
 },
 afterFocus: {
  typeFunction
 },
 afterBlur: {
  typeFunction
 },
 afterUpload: {
  typeFunction
 },
 uploadJson: {
  typeString
 },
 fileManagerJson: {
  typeFunction
 },
 allowPreviewEmoticons: {
  typeBoolean,
  defaulttrue
 },
 allowImageUpload: {
  typeBoolean,
  defaulttrue
 },
 allowFlashUpload: {
  typeBoolean,
  defaulttrue
 },
 allowMediaUpload: {
  typeBoolean,
  defaulttrue
 },
 allowFileUpload: {
  typeBoolean,
  defaulttrue
 },
 allowFileManager: {
  typeBoolean,
  defaultfalse
 },
 fontSizeTable: {
  typeArray,
  defaultfunction () {
  return ['9px''10px''12px''14px''16px''18px''24px''32px']
  }
 },
 imageTabIndex: {
  typeNumber,
  default0
 },
 formatUploadUrl: {
  typeBoolean,
  defaulttrue
 },
 fullscreenShortcut: {
  typeBoolean,
  defaultfalse
 },
 extraFileUploadParams: {
  typeArray,
  defaultfunction () {
  return []
  }
 },
 filePostName: {
  typeString,
  default'imgFile'
 },
 fillDescAfterUploadImage: {
  typeBoolean,
  defaultfalse
 },
 afterSelectFile: {
  typeFunction
 },
 pagebreakHtml: {
  typeString,
  default'<hr style=”page-break-after: always;” class=”ke-pagebreak” />'
 },
 allowImageRemote: {
  typeBoolean,
  defaulttrue
 },
 autoHeightMode: {
  typeBoolean,
  defaultfalse
 },
 fixToolBar: {
  typeBoolean,
  defaultfalse
 },
 tabIndex: {
  typeNumber
 }
 },
 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)
 }
 },
 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,
  afterChangefunction () {
  _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"
   @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 {
  editorText'直接初始化值'// 双向同步的变量
  editorTextCopy'' // content-change 事件回掉改变的对象
 }
 },
 methods: {
 onContentChange (val) {
  this.editorTextCopy = val;
  window.console.log(this.editorTextCopy)
 },
 afterChange () {
 }
 }
}
</script>

上述内容就是kindeditor富文本编辑器怎么在vue项目中使用,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注亿速云行业资讯频道。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI

开发者交流群×