CKEditor集成Vue项目

1.下载模块化依赖并引入

npm i ckeditor4-vue
import CKEditor from "ckeditor4-vue";


:使用
components: {
		ckeditor: CKEditor.component
	},

2.下载代码包

地址:https://ckeditor.com/ckeditor-4/download/ 在解压后放入本项目或者CDN上

3.标签使用方式

<ckeditor
			@ready="editorReady"
			@focus="editorFocus"
			:editor-url="editorUrl"
			v-model="editorData"
			:config="editorConfig"
			ref="editor"
		>
</ckeditor>

备注 @ready
     @focus
     :editor-url
     :config
     ref="editor"
  这几个属性必传,但v-model可以不传,由于延迟或异步会导致无法实时同步取到编辑器的值,所以使用ref来取值

 4.重要的实例:

editorUrl:'',	解压包中ckeditor.js的访问路径	
editorConfig: {
				title: "welcome to use editor!!",
				language: "zh-cn",
				filebrowserImageUploadUrl: "/apis/content/upload-file",
				//extraPlugins: ["uploadfile", "uploadimg"], //自定义上传的按钮
				toolbar: [
					// [ 'Source', '-', 'Save', 'NewPage', 'Print', '-', 'Templates' ] ,
					[
						"Undo",
						"Redo",
						"-",
						"Cut",
						"Copy",
						"Paste",
						"PasteText",
						"PasteFromWord"
					],
					[/*'Find', 'Replace', '-',*/ "SelectAll" /* '-', 'Scayt'*/],
					// [ 'Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField' ] ,
					[
						"Table",
						"HorizontalRule",
						"Smiley",
						"SpecialChar" /* 'PageBreak',*/
					],
					[/*'ShowBlocks',*/ "Maximize"],
					"/",
					["Link", "Unlink" /* 'Anchor'*/],
					[
						"Bold",
						"Italic",
						"Underline",
						"Strike",
						"TextColor",
						"BGColor",
						"Subscript",
						"Superscript",
						"-",
						"CopyFormatting",
						"RemoveFormat"
					],
					["uploadfile", "uploadimg"],
					[
						"NumberedList",
						"BulletedList",
						"-",
						"Outdent",
						"Indent",
						"-",
						"Blockquote",
						"CreateDiv",
						"-",
						"JustifyLeft",
						"JustifyCenter",
						"JustifyRight",
						"JustifyBlock",
						"-",
						"BidiLtr",
						"BidiRtl"
					],
					"/",
					["Styles", "Format", "Font", "FontSize"]
				]
			}

5.ckeditor自定义按钮的方法:

   (1)在解压包plugins目录下新建目录,可以命名为功能名称

   (2)在新建的目录下新建icon.png图标文件和plugin.js

    

(function(){
    //Section 1 : 按下自定义按钮时执行的代码
    var action = {
        exec:function(editor){
            editor.uploadimgHook(editor);
        }
    },
    //Section 2 : 创建自定义按钮、绑定方法
    type = 'uploadimg';
    CKEDITOR.plugins.add(type,{
        init:function(editor){
            editor.addCommand(type,action);
            editor.ui.addButton('uploadimg',{
                label:'上传图片',
                icon: this.path + 'icon.png',
                command:type
            });
        }
    });
})();

6.在代码中引入自定义i模块

步骤3的数组:extraPlugins,切记名称一定要对上

7.在代码中使用刚刚自定义模块,

定义一个函数用于刚刚的钩子函数并在editorReady事件中绑定:

editor.uploadimgHook = this.uploadimgHook;

好了,现在可以在uploadimgHook方法里使用自定义按钮了

bye~~~

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值