1.引入

<script type="text/javascript" src="/plugin/ckeditor5/ckeditor.js"></script>

2.html

<div class="form-group col-lg-12">
<label class="control-label col-lg-3 text-right"><span class="control-label required-mark"></span>内容:</label>
<textarea class="form-control-erbi col-lg-5" name="editor" id="editor" /></textarea>
</div>

3.样式

<style>
.ck-editor__main{
width:75%;
padding-right: 0;
float: right;
} .ck-editor__editable {
min-height: 200px;
}
</style>

4.启动

var myEditor = null;
window.onload = function(){
ClassicEditor
.create(document.querySelector("#editor"), {
ckfinder: {
uploadUrl: '/admin.php/Common/ck_editor?command=QuickUpload&type=Files&responseType=json'
}
})
.then(editor => {
myEditor = editor;
// 设置初始值
myEditor.setData('');
})
.catch(error => {
console.error(error);
});
}

5.图片上传后台,文件名默认为upload

public function ck_editor(){
$config = array(
"savePath" => "./site_upload/ck_editor/" , //存储文件夹
"maxSize" => 1000000 , //允许的文件最大尺寸,单位KB
"allowFiles" => array( ".gif" , ".png" , ".jpg" , ".jpeg" , ".bmp" ) //允许的文件格式
); $up = new Uploader( "upload" , $config );
$info = $up->getFileInfo();
$info['url'] = substr($info['url'],1);
$host_name = Func::getHostName();
$url = 'http://' . $host_name . $info['url'];
$qiniu = new QiniuImg();
$ext = pathinfo($url, PATHINFO_EXTENSION);
$name = time() . mt_rand() . '.' . $ext;
$s = $qiniu->up($url, $name, config('app.qiniu.bucket'));
if($s){
@unlink('.'.$info['url']);
$info['url'] = config('cdn_host').$name;
}
if ($info) {
$this->json->setAttr('uploaded',true);
$this->json->setAttr('url',[$info['url']]);
$this->json->Send();
} else {
$this->json->setAttr('uploaded',false);
$this->json->setErr(10099,'上传失败');
$this->json->Send();
}
}

6.获取内容

var htmlStr=myEditor.getData();
$('#editor').val(htmlStr);

配置自己的tarbar

var myEditor = null;
window.onload = function(){
ClassicEditor
.create(document.querySelector("#editor"), {
toolbar: ["undo", "redo", "|", "alignment", "bold", "italic", "blockQuote", "imageTextAlternative", "imageUpload", "heading", "link", "numberedList", "bulletedList"],
ckfinder: {
uploadUrl: '/admin.php/Common/ck_editor?command=QuickUpload&type=Files&responseType=json'
}
})
.then(editor => {
myEditor = editor;
// 设置初始值
myEditor.setData('');
})
.catch(error => {
console.error(error);
});
}

CKEditor5 基本使用的更多相关文章

  1. CKEditor5 + ckfinder3(php)

    CKEditor5资源下载,这里我们选择ckeditor5-build-classic下载: https://ckeditor.com/ckeditor-5-builds/download/ ckfi ...

  2. CKEditor5 + vue2.0 自定义图片上传、highlight、字体等用法

    因业务需求,要在 vue2.0 的项目里使用富文本编辑器,经过调研多个编辑器,CKEditor5 支持 vue,遂采用.因 CKEditor5 文档比较少,此处记录下引用和一些基本用法. CKEdit ...

  3. ckeditor5 安装高亮,颜色插件

    ckeditor5 安装高亮插件 1.准备 git clone -b stable https://github.com/ckeditor/ckeditor5-build-classic.git cd ...

  4. ckeditor5 增加居中alignment

    https://ckeditor.com/docs/ckeditor5/latest/builds/guides/integration/installing-plugins.html 克隆下来 gi ...

  5. ckeditor5富文本编辑器在vue中的使用

    安装依赖: npm install --save @ckeditor/ckeditor5-vue @ckeditor/ckeditor5-build-classic 要创建编辑器实例,必须首先将编辑器 ...

  6. CKEditor5 使用第二天 获取回传数据,图片上传

    1.当系统中存在编辑功能时,需要将数据库中数据回显到页面,因此采用了最一般的方法,通过隐藏的input标签存贮,在通过CkEditor5中的setData方法将数据赋值到富文本框中 <texta ...

  7. CKEditor5 输入文字时拼音和汉字同时输入问题

    在使用 CKEditor5 + vue 时,出现输入文字时,拼音和文字一起输入到编辑器到问题.与之前项目中使用 ckeditor 的区别是,这次项目是在 python 架构下局部引入 ckeditor ...

  8. Ckeditor5显示css样式

    Ckeditor5在编辑模式是通过js加载样式的,但是在显示时没有提供,官方提供了两种方式来实现. https://ckeditor.com/docs/ckeditor5/latest/builds/ ...

  9. ckeditor5字体颜色,字体背景颜色设置显示

    在config.js中添加相关代码: config.allowedContent=true;//关闭标签过滤, config.colorButton_enableAutomatic = true; c ...

随机推荐

  1. python-字符串前面添加u,r,b的含义

    u/U:表示unicode字符串 不是仅仅是针对中文, 可以针对任何的字符串,代表是对字符串进行unicode编码. 一般英文字符在使用各种编码下, 基本都可以正常解析, 所以一般不带u:但是中文, ...

  2. (转)mysql数据文件解析

    一 数据文件 在 MySQL中每一个数据库都会在定义好(或者默认)的数据目录下存在一个以数据库名字命名的文件夹,用来存放该数据库中各种表数据文件.不同的 MySQL存储引擎有各自不同的数据文件,存放位 ...

  3. 表单验证——JqueryValidator、BootstrapValidator

    表单验证两种方式: 1.JqueryValidator <!DOCTYPE html> <html lang="en"> <head> < ...

  4. cheng gong de daima

    /** * Copyright (c) 2012-2016 ebizwindow, Inc. All rights reserved. * * Permission is hereby granted ...

  5. linux rz sz

    对于经常使用Linux系统的人员来说,少不了将本地的文件上传到服务器或者从服务器上下载文件到本地,rz / sz命令很方便的帮我们实现了这个功能,但是很多Linux系统初始并没有这两个命令.今天,我们 ...

  6. Junit4用法

    序号 方法和描述 1 void assertEquals(boolean expected, boolean actual) 检查两个变量或者等式是否平衡 2 void assertTrue(bool ...

  7. Linux基础命令---zcat

    zcat 解压有gzip压缩的文件,将解压结果送到标准输出. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.SUSE.openSUSE.Fedora. 1.语法       z ...

  8. Vue源码解析之nextTick

    Vue源码解析之nextTick 前言 nextTick是Vue的一个核心功能,在Vue内部实现中也经常用到nextTick.但是,很多新手不理解nextTick的原理,甚至不清楚nextTick的作 ...

  9. ES6学习--箭头函数

    1. 箭头函数基本形式 let func = (num) => num; let func = () => num; let sum = (num1,num2) => num1 + ...

  10. troubleshooting-Kerberos 鉴权异常

    ERROR transport.TSaslTransport: SASL negotiation failurejavax.security.sasl.SaslException: GSS initi ...