项目作者: PeakTai

项目描述 :
An html5 wysiwyg editor for vue
高级语言: JavaScript
项目地址: git://github.com/PeakTai/vue-html5-editor.git
创建时间: 2016-06-16T11:13:55Z
项目社区:https://github.com/PeakTai/vue-html5-editor

开源协议:Apache License 2.0

下载


简介 Intro

Vue-html5-editor是一个Vue的富文本编辑器插件,简洁灵活可扩展,适用于vue2.0以上版本,支持IE11.

Vue-html5-editor is an html5 wysiwyg editor for vue,easy and flexible,compatible with Vue.js 2.0+,support IE11.

screenshot

点击查看演示效果 Demo is here

安装 Installation

Npm

  1. npm install vue-html5-editor --save-dev

引入并安装作为全局组件

import and install as global component

  1. import Vue from 'vue'
  2. import VueHtml5Editor from 'vue-html5-editor'
  3. Vue.use(VueHtml5Editor,options);

同样你也可以作为局部组件使用,方便在不同的场景里使用不同的配置.

  1. const editor1 = new VueHtml5Editor(options1)
  2. const app1 = new Vue({
  3. components:{
  4. editor1
  5. }
  6. })
  7. const editor2 = new VueHtml5Editor(options2)
  8. const app2 = new Vue({
  9. components:{
  10. editor2
  11. }
  12. })

浏览器直接使用 browser

  1. <script src="serverpath/vue.js"></script>
  2. <script src="serverpath/vue-html5-editor.js"></script>

通过全局变量VueHtml5Editor来安装.

Install using global variable VueHtml5Editor.

  1. Vue.use(VueHtml5Editor, options)

使用说明 Usage

模板代码如下:

template code as follows:

  1. <vue-html5-editor :content="content" :height="500"></vue-html5-editor>

options

  1. Vue.use(VueHtml5Editor, {
  2. // 全局组件名称,使用new VueHtml5Editor(options)时该选项无效
  3. // global component name
  4. name: "vue-html5-editor",
  5. // 是否显示模块名称,开启的话会在工具栏的图标后台直接显示名称
  6. // if set true,will append module name to toolbar after icon
  7. showModuleName: false,
  8. // 自定义各个图标的class,默认使用的是font-awesome提供的图标
  9. // custom icon class of built-in modules,default using font-awesome
  10. icons: {
  11. text: "fa fa-pencil",
  12. color: "fa fa-paint-brush",
  13. font: "fa fa-font",
  14. align: "fa fa-align-justify",
  15. list: "fa fa-list",
  16. link: "fa fa-chain",
  17. unlink: "fa fa-chain-broken",
  18. tabulation: "fa fa-table",
  19. image: "fa fa-file-image-o",
  20. hr: "fa fa-minus",
  21. eraser: "fa fa-eraser",
  22. undo: "fa-undo fa",
  23. "full-screen": "fa fa-arrows-alt",
  24. info: "fa fa-info",
  25. },
  26. // 配置图片模块
  27. // config image module
  28. image: {
  29. // 文件最大体积,单位字节 max file size
  30. sizeLimit: 512 * 1024,
  31. // 上传参数,默认把图片转为base64而不上传
  32. // upload config,default null and convert image to base64
  33. upload: {
  34. url: null,
  35. headers: {},
  36. params: {},
  37. fieldName: {}
  38. },
  39. // 压缩参数,默认使用localResizeIMG进行压缩,设置为null禁止压缩
  40. // compression config,default resize image by localResizeIMG (https://github.com/think2011/localResizeIMG)
  41. // set null to disable compression
  42. compress: {
  43. width: 1600,
  44. height: 1600,
  45. quality: 80
  46. },
  47. // 响应数据处理,最终返回图片链接
  48. // handle response data,return image url
  49. uploadHandler(responseText){
  50. //default accept json data like {ok:false,msg:"unexpected"} or {ok:true,data:"image url"}
  51. var json = JSON.parse(responseText)
  52. if (!json.ok) {
  53. alert(json.msg)
  54. } else {
  55. return json.data
  56. }
  57. }
  58. },
  59. // 语言,内建的有英文(en-us)和中文(zh-cn)
  60. //default en-us, en-us and zh-cn are built-in
  61. language: "zh-cn",
  62. // 自定义语言
  63. i18n: {
  64. //specify your language here
  65. "zh-cn": {
  66. "align": "对齐方式",
  67. "image": "图片",
  68. "list": "列表",
  69. "link": "链接",
  70. "unlink": "去除链接",
  71. "table": "表格",
  72. "font": "文字",
  73. "full screen": "全屏",
  74. "text": "排版",
  75. "eraser": "格式清除",
  76. "info": "关于",
  77. "color": "颜色",
  78. "please enter a url": "请输入地址",
  79. "create link": "创建链接",
  80. "bold": "加粗",
  81. "italic": "倾斜",
  82. "underline": "下划线",
  83. "strike through": "删除线",
  84. "subscript": "上标",
  85. "superscript": "下标",
  86. "heading": "标题",
  87. "font name": "字体",
  88. "font size": "文字大小",
  89. "left justify": "左对齐",
  90. "center justify": "居中",
  91. "right justify": "右对齐",
  92. "ordered list": "有序列表",
  93. "unordered list": "无序列表",
  94. "fore color": "前景色",
  95. "background color": "背景色",
  96. "row count": "行数",
  97. "column count": "列数",
  98. "save": "确定",
  99. "upload": "上传",
  100. "progress": "进度",
  101. "unknown": "未知",
  102. "please wait": "请稍等",
  103. "error": "错误",
  104. "abort": "中断",
  105. "reset": "重置"
  106. }
  107. },
  108. // 隐藏不想要显示出来的模块
  109. // the modules you don't want
  110. hiddenModules: [],
  111. // 自定义要显示的模块,并控制顺序
  112. // keep only the modules you want and customize the order.
  113. // can be used with hiddenModules together
  114. visibleModules: [
  115. "text",
  116. "color",
  117. "font",
  118. "align",
  119. "list",
  120. "link",
  121. "unlink",
  122. "tabulation",
  123. "image",
  124. "hr",
  125. "eraser",
  126. "undo",
  127. "full-screen",
  128. "info",
  129. ],
  130. // 扩展模块,具体可以参考examples或查看源码
  131. // extended modules
  132. modules: {
  133. //omit,reference to source code of build-in modules
  134. }
  135. })

组件属性 attributes

  1. <editor :content="content" :height="500" :z-index="1000" :auto-height="true" :show-module-name="false"></editor>

content

编辑内容

The html content to edit

height

编辑器高度,如果设置了auto-height为true,将设置为编辑器的最小高度.

The height or min-height ( if auto-height is true ) of editor.

z-index

层级,将会设置编辑器容量的z-index样式属性,默认为1000.

Sets z-index style property of editor,default 1000.

auto-height

是否自动根据内容控制编辑器高度,默认为true.

Resize editor height automatically,default true.

show-module-name

局部设置是否显示模块名称,会覆盖全局的设定.

Set showModuleName locally.

事件

  1. <editor @change="updateData"></editor>

change

每次内容有变动时触发,回传改变后的内容.

Emited when the content changes,and pass the current content as event data.

License

Apache-2.0