Vue 2.x 使用CKEditor 的入坑(后续)

元皓
• 阅读 10529

上篇文章记录了vue如何引入ckeditor4,这篇主要记录下ckeditor数据获取等,
1.实现了编辑器初始化完成后赋值,可用于编辑新的文章
2.监听编辑器内容改变,实时获取最新数据,用于保存
附上老夫的demo

        <template>
          <div class="editor">
            <textarea name="editor" id="editor" rows="10" cols="80"></textarea>
          </div>
        </template>
        <script>
        import CKEDITOR from 'CKEDITOR'
        export default {
          props: {
            content: {
              type: String,
              default: '请输入您的内容'
            }
          },
          data () {
            return {}
          },
          mounted () {
            this.initCKEditor()
          },
          methods: {
            initCKEditor: function () {
              CKEDITOR.addCss(
                'figure[class*=easyimage-gradient]::before { content: ""; position: absolute; top: 0; bottom: 0; left: 0; right: 0; }' +
                  'figure[class*=easyimage-gradient] figcaption { position: relative; z-index: 2; }' +
                  '.easyimage-gradient-1::before { background-image: linear-gradient( 135deg, rgba( 115, 110, 254, 0 ) 0%, rgba( 66, 174, 234, .72 ) 100% ); }' +
                  '.easyimage-gradient-2::before { background-image: linear-gradient( 135deg, rgba( 115, 110, 254, 0 ) 0%, rgba( 228, 66, 234, .72 ) 100% ); }'
              )
              // CKEditor 配置项
              CKEDITOR.replace('editor', {
                toolbar: [
                  {
                    name: 'clipboard',
                    items: ['PasteFromWord', '-', 'Undo', 'Redo']
                  },
                  {
                    name: 'basicstyles',
                    items: [
                      'Bold',
                      'Italic',
                      'Underline',
                      'Strike',
                      'RemoveFormat',
                      'Subscript',
                      'Superscript'
                    ]
                  },
                  {
                    name: 'links',
                    items: ['Link', 'Unlink']
                  },
                  {
                    name: 'paragraph',
                    items: [
                      'NumberedList',
                      'BulletedList',
                      '-',
                      'Outdent',
                      'Indent',
                      '-',
                      'Blockquote'
                    ]
                  },
                  {
                    name: 'insert',
                    items: ['Image', 'Table']
                  },
                  '/',
        
                  {
                    name: 'styles',
                    items: ['Format', 'Font', 'FontSize']
                  },
                  {
                    name: 'colors',
                    items: ['TextColor', 'BGColor', 'CopyFormatting']
                  },
                  {
                    name: 'align',
                    items: [
                      'JustifyLeft',
                      'JustifyCenter',
                      'JustifyRight',
                      'JustifyBlock'
                    ]
                  },
                  {
                    name: 'tools',
                    items: ['Maximize']
                  },
                  {
                    name: 'document',
                    items: ['Print', 'Source']
                  }
                ],
        
                // Configure your file manager integration. This example uses CKFinder 3 for PHP.
                // filebrowserBrowseUrl: '/apps/ckfinder/3.4.4/ckfinder.html',
                // filebrowserImageBrowseUrl: '/apps/ckfinder/3.4.4/ckfinder.html?type=Images',
                // filebrowserUploadUrl: '/apps/ckfinder/3.4.4/core/connector/php/connector.php?command=QuickUpload&type=Files',
                filebrowserImageUploadUrl: '/upload/image.json',
                image_previewText: '',
                // Sometimes applications that convert HTML to PDF prefer setting image width through attributes instead of CSS styles.
                // For more information check:
                //  - About Advanced Content Filter: https://ckeditor.com/docs/ckeditor4/latest/guide/dev_advanced_content_filter
                //  - About Disallowed Content: https://ckeditor.com/docs/ckeditor4/latest/guide/dev_disallowed_content
                //  - About Allowed Content: https://ckeditor.com/docs/ckeditor4/latest/guide/dev_allowed_content_rules
                disallowedContent: 'img{width,height,float}',
                extraAllowedContent: 'img[width,height,align];span{background}',
        
                // Enabling extra plugins, available in the full-all preset: https://ckeditor.com/cke4/presets
                extraPlugins:
                  'colorbutton,font,justify,print,tableresize,uploadimage,pastefromword,liststyle',
        
                /** ********************* File management support ***********************/
                // In order to turn on support for file uploads, CKEditor has to be configured to use some server side
                // solution with file upload/management capabilities, like for example CKFinder.
                // For more information see https://ckeditor.com/docs/ckeditor4/latest/guide/dev_ckfinder_integration
        
                // Uncomment and correct these lines after you setup your local CKFinder instance.
                // filebrowserBrowseUrl: 'http://example.com/ckfinder/ckfinder.html',
                // filebrowserUploadUrl: 'http://example.com/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
                /** *********************  File management support ***********************/
        
                // Make the editing area bigger than default.
                height: 400,
                width: '100%',
                // An array of stylesheets to style the WYSIWYG area.
                // Note: it is recommended to keep your own styles in a separate file in order to make future updates painless.
                contentsCss: [
                  'http://cdn.ckeditor.com/4.11.2/full-all/contents.css',
                  'assets/css/pastefromword.css'
                ],
                easyimage_styles: {
                  gradient1: {
                    group: 'easyimage-gradients',
                    attributes: {
                      class: 'easyimage-gradient-1'
                    },
                    label: 'Blue Gradient',
                    icon:
                      'https://ckeditor.com/docs/ckeditor4/4.11.2/examples/assets/easyimage/icons/gradient1.png',
                    iconHiDpi:
                      'https://ckeditor.com/docs/ckeditor4/4.11.2/examples/assets/easyimage/icons/hidpi/gradient1.png'
                  },
                  gradient2: {
                    group: 'easyimage-gradients',
                    attributes: {
                      class: 'easyimage-gradient-2'
                    },
                    label: 'Pink Gradient',
                    icon:
                      'https://ckeditor.com/docs/ckeditor4/4.11.2/examples/assets/easyimage/icons/gradient2.png',
                    iconHiDpi:
                      'https://ckeditor.com/docs/ckeditor4/4.11.2/examples/assets/easyimage/icons/hidpi/gradient2.png'
                  },
                  noGradient: {
                    group: 'easyimage-gradients',
                    attributes: {
                      class: 'easyimage-no-gradient'
                    },
                    label: 'No Gradient',
                    icon:
                      'https://ckeditor.com/docs/ckeditor4/4.11.2/examples/assets/easyimage/icons/nogradient.png',
                    iconHiDpi:
                      'https://ckeditor.com/docs/ckeditor4/4.11.2/examples/assets/easyimage/icons/hidpi/nogradient.png'
                  }
                },
                language: 'zh-cn',
                // This is optional, but will let us define multiple different styles for multiple editors using the same CSS file.
                bodyClass: 'document-editor',
        
                // Reduce the list of block elements listed in the Format dropdown to the most commonly used.
                format_tags: 'p;h1;h2;h3;pre',
        
                // Simplify the Image and Link dialog windows. The 'Advanced' tab is not needed in most cases.
                removeDialogTabs: 'image:advanced;link:advanced',
        
                // Define the list of styles which should be available in the Styles dropdown list.
                // If the 'class' attribute is used to style an element, make sure to define the style for the class in 'mystyles.css'
                // (and on your website so that it rendered in the same way).
                // Note: by default CKEditor looks for styles.js file. Defining stylesSet inline (as below) stops CKEditor from loading
                // that file, which means one HTTP request less (and a faster startup).
                // For more information see https://ckeditor.com/docs/ckeditor4/latest/guide/dev_styles
                stylesSet: [
                  /* Inline Styles */
                  {
                    name: 'Marker',
                    element: 'span',
                    attributes: {
                      class: 'marker'
                    }
                  },
                  {
                    name: 'Cited Work',
                    element: 'cite'
                  },
                  {
                    name: 'Inline Quotation',
                    element: 'q'
                  },
        
                  /* Object Styles */
                  {
                    name: 'Special Container',
                    element: 'div',
                    styles: {
                      padding: '5px 10px',
                      background: '#eee',
                      border: '1px solid #ccc'
                    }
                  },
                  {
                    name: 'Compact table',
                    element: 'table',
                    attributes: {
                      cellpadding: '5',
                      cellspacing: '0',
                      border: '1',
                      bordercolor: '#ccc'
                    },
                    styles: {
                      'border-collapse': 'collapse'
                    }
                  },
                  {
                    name: 'Borderless Table',
                    element: 'table',
                    styles: {
                      'border-style': 'hidden',
                      'background-color': '#E6E6FA'
                    }
                  },
                  {
                    name: 'Square Bulleted List',
                    element: 'ul',
                    styles: {
                      'list-style-type': 'square'
                    }
                  }
                ]
              })
              //  CKEditor 初始化完成加载数据
              CKEDITOR.on('instanceReady', e => {
                this.setContent()
              })
        
              //  CKEditor 数据改变-监听
              CKEDITOR.instances.editor.on('change', e => {
                this.getContent()
              })
            },
            setContent () {
              CKEDITOR.instances.editor.setData(this.content)
            },
            getContent () {
               // 参照vue子组件传值给
              this.$emit('catchData', CKEDITOR.instances.editor.getData())
            }
          }
        }
        </script>
点赞
收藏
评论区
推荐文章
blmius blmius
4年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Wesley13 Wesley13
3年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
美凌格栋栋酱 美凌格栋栋酱
7个月前
Oracle 分组与拼接字符串同时使用
SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
Wesley13 Wesley13
3年前
Java日期时间API系列31
  时间戳是指格林威治时间1970年01月01日00时00分00秒起至现在的总毫秒数,是所有时间的基础,其他时间可以通过时间戳转换得到。Java中本来已经有相关获取时间戳的方法,Java8后增加新的类Instant等专用于处理时间戳问题。 1获取时间戳的方法和性能对比1.1获取时间戳方法Java8以前
陈占占 陈占占
3年前
ckeditor4 代码插件亮度与HTML显示代码的亮度问题
1、代码插件亮度在ckeditor4的官网下载,下载后,把解压的文件codesnippet添加到ckeditor4下的plugins文件夹下。之后更改ckeditor文件夹下的config.js的文件。添加如下语句:config.extraPlugins'clipboard,lineutils,widget,dialog,codesnippet';
Jacquelyn38 Jacquelyn38
4年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
Jacquelyn38 Jacquelyn38
4年前
我熬夜开发了一款简约实用、支持多平台的Markdown在线编辑器(开源)
前言之前,一直想开发一款属于自己的Markdown编辑器,主要是自己平常写文章可以更加灵活操作,另外扩宽自己的视野也是非常不错的选择啊!所以在周末就决定玩耍一番。首先我调研了很多线上热门的md编辑器,都很优秀。不为超过他们,主要自己用着舒服点。这篇文章主要是记录下我是如何从0到1是完成一款还算拿得出手的Markdown编辑器。完成项目一览调研Markdown
Wesley13 Wesley13
3年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
3年前
JavaWeb 调用接口
JavaWeb 如何调用接口CreateTime2018年4月2日19:04:29Author:Marydon1.所需jar包!(https://oscimg.oschina.net/oscnet/0f139
Stella981 Stella981
3年前
CKEditor5 + vue2.0 自定义图片上传、highlight、字体等用法
  因业务需求,要在vue2.0的项目里使用富文本编辑器,经过调研多个编辑器,CKEditor5 支持 vue,遂采用。因CKEditor5 文档比较少,此处记录下引用和一些基本用法。CKEditor5官网https://ckeditor.com/docs/ckeditor5/latest/builds/guides/overview.
元皓
元皓
Lv1
后来我们温一壶酒你我都像最初的模样
文章
4
粉丝
0
获赞
0