vue2 引入ckeditor富文本

2024-04-30 17:04

本文主要是介绍vue2 引入ckeditor富文本,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

编辑器测试

npm install  @ckeditor/ckeditor5-vue2
npm install  ckeditor5-lvjiajia-zsdl-v2

components/Ckedit/index.vue

<template><div id="app"><ckeditor:editor="editor"v-model="editorData":config="editorConfig"></ckeditor><button v-show="false" @click="onClick">查看编辑器内容源码</button></div>
</template><script>
import Editor from "ckeditor5-lvjiajia-zsdl-v2/build/ckeditor";
import MyUploadAdapter from './MyUploadAdapter';//定义上传适配器
function MyCustomUploadAdapterPlugin( editor ) {editor.plugins.get( 'FileRepository' ).createUploadAdapter = ( loader ) => {// 第二个参数设置上传图片的地址return new MyUploadAdapter( loader, process.env.VUE_APP_BASE_API + "?action=custom_file_upload" );};
};
export default {name: "Ckedit",props: ['value'],data() {return {// ckeditor配置开始 -------------------------------------------------editor: Editor,editorData: this.value, // 将父组件传递过来的值作为初始值editorConfig: {extraPlugins: [ MyCustomUploadAdapterPlugin  // 添加上传适配器],placeholder: "输入正文",// 编辑器的配置toolbar: {items: ["undo","redo","|","heading","|","bold",// "fontFamily", // 字体样式// "fontSize", // 字体大小// {//   label: '列表',//   icon://     '<svg t="1678948802831" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1010" width="200" height="200"><path d="M132.608 204.288m-66.56 0a66.56 66.56 0 1 0 133.12 0 66.56 66.56 0 1 0-133.12 0Z" p-id="1011"></path><path d="M962.01728 158.80192l-680.68352 0.3584-0.04096 84.44928 680.7552-0.3584-0.03072-84.44928z" p-id="1012"></path><path d="M132.608 512m-66.56 0a66.56 66.56 0 1 0 133.12 0 66.56 66.56 0 1 0-133.12 0Z" p-id="1013"></path><path d="M281.33376 466.87232l-0.04096 84.44928 680.7552-0.3584-0.03072-84.44928-680.68352 0.3584z" p-id="1014"></path><path d="M132.608 819.712m-66.56 0a66.56 66.56 0 1 0 133.12 0 66.56 66.56 0 1 0-133.12 0Z" p-id="1015"></path><path d="M281.33376 775.59808l-0.04096 84.44928 680.7552-0.3584-0.03072-84.44928-680.68352 0.3584z" p-id="1016"></path></svg>',//   items: ['bulletedList', 'numberedList']// },"bulletedList","numberedList","horizontalLine","blockQuote","alignment","todoList","findAndReplace",{label: "更多",icon: false,items: ["italic","strikethrough","underline","superscript","subscript","indent","outdent",// 'code',"codeBlock","removeFormat",],},"|","fontBackgroundColor","fontColor","highlight","|","imageUpload",// 'mediaEmbed',"link","specialCharacters","insertTable","|","htmlEmbed","sourceEditing",// "pageBreak", // 分页符// More of toolbar's config.// ...],shouldNotGroupWhenFull: true,},// 标题的配置heading: {options: [{model: "paragraph",title: "正文",class: "ck-heading_paragraph",},{model: "heading1",view: "h1",title: "H1 大标题",class: "ck-heading_heading1",},{model: "heading2",view: "h2",title: "H2 中标题",class: "ck-heading_heading2",},{model: "heading3",view: "h3",title: "H3 小标题",class: "ck-heading_heading3",},],},// 缩进的配置indentBlock: {offset: 2,unit: "em",},// html映射htmlEmbed: {showPreviews: true,},// 启用所有HTML功能htmlSupport: {allow: [{name: /.*/,attributes: true,classes: true,styles: true,},],},// 图像image: {toolbar: ["toggleImageCaption", "|", "imageStyle:aligncenter"],},},};},watch: {value(newValue) {// 监听父组件传递的值的变化,更新子组件中的编辑器内容this.editorData = newValue;},editorData(newData) {// 监听编辑器内容的变化,将变化的内容通过事件传递给父组件this.$emit('input', newData);}},methods: {onClick() {this.neirong = this.editorData;console.log(this.neirong, "这是内容-----");},},
};
</script><style lang="scss">
body {margin: 0;padding: 0;
}
#app {width: 100%;margin: 0 auto;background-color: #f1f3f4;
}// 工具栏
.ck-toolbar,
.ck-toolbar_grouping {// margin-top: 72px !important;// position: fixed !important;// top: 72px !important;width: 100% !important;// height: 72px !important;// border-bottom: 1px solid #ccced1 !important;box-shadow: none !important;border: none !important;// background-color: #f1f3f4 !important;// background-color: pink !important;z-index: 99 !important;
}
.ck-toolbar__items {width: 100% !important;display: flex !important;justify-content: center !important;// margin-left: 100px !important;
}
// 列表的两个图标禁止点击
.ck-splitbutton__action {pointer-events: none !important;
}// 编辑区域
.ck-sticky-panel__content {width:100%!important;//position: fixed !important;// top: 72px !important;z-index: 999 !important;
}.classone {.ck-editor__editable_inline {margin-top: 208px !important;}
}
// .classtwo {
//   margin-top: 176px !important;
// }.ck-editor__main {padding-top: 0px !important;
}.ck-editor,
.ck-blurred,
.ck-editor__editable_inline {width: 100%;// margin-top: 176px;// 208px 176px//margin-left: 266px;min-height: 640px !important;// padding: 20px 72px !important;border:#4a4a4a 1px solid !important;box-shadow: none !important;// z-index: -100 !important;// border: 1px solid green;// background-color: pink !important;/* border: 1px solid #ffffff !important; */.ck-content {padding: 0 0px !important;}// 编辑器的视频的宽度video {width: 550px !important;height: 300px !important;}// ckeditorh1 {margin: 24px 0 !important;font-size: 20px !important;font-weight: 700 !important;color: #4a4a4a !important;line-height: 1.75 !important;padding: 0 !important;}h2 {margin: 24px 0 !important;font-size: 19px !important;font-weight: 700 !important;color: #4a4a4a !important;line-height: 1.75 !important;padding: 0 !important;}h3 {margin: 24px 0 !important;font-size: 18px !important;font-weight: 700 !important;color: #4a4a4a !important;line-height: 1.75 !important;padding: 0 !important;}p {margin: 24px 0 !important;font-size: 17px !important;color: #4a4a4a !important;line-height: 1.75 !important;padding: 0 !important;}figure {margin: 24px auto !important;}blockquote {margin: 24px 0 !important;h1,h2,h3,p {margin: 3px 0 !important;color: #999999 !important;font-style: normal;}}tbody,.table {margin: 24px 0 !important;max-width: 628px !important;color: #4a4a4a !important;// margin: 0 auto !important;}// code {//   margin: 24px 0 !important;// }// 引用的效果pre {margin: 24px 0 !important;-webkit-text-stroke-width: 0px;background-color: rgb(251, 251, 251);border-color: rgb(221, 221, 221);color: rgb(51, 51, 51);border-top-width: 1px;border-bottom-width: 1px;border-left-width: 4px;border-right-width: 1px;border-image: initial;border-radius: 1px;border-style: solid;font-size: 17px;font-weight: normal;letter-spacing: normal;margin: 3px 0px 5px;padding: 7px 18px;orphans: 2;overflow-wrap: normal !important;overflow: auto;text-align: left;text-decoration-color: initial;text-decoration-style: initial;text-indent: 0px;text-transform: none;white-space: pre !important;widows: 2;word-break: normal !important;word-spacing: 0px;}
}.ck-content {ul,ol {font-size: 17px !important;}li {color: #4a4a4a;margin: 8px 0 8px 25px !important;}
}// 添加废话,测试jenkins上传代码
.ck-content .todo-list .todo-list__label > input[checked]:before {background: #d1d1d1;border-color: #d1d1d1;
}
.ck-content .todo-list .todo-list__label > input:before {border-color: #d1d1d1;
}// 源代码的展示
.ck-source-editing-area {margin-top: 40px !important;z-index: 99999 !important;
}// 提升message提示消息的层级,避免被顶部导航栏遮住
.messageIndex {z-index: 99999 !important;
}
</style>

在main.js 注册全局组件

// 整合Ckedit富文本
import Ckedit from "@/components/Ckedit"
Vue.component('Ckedit', Ckedit)import CKEditor from '@ckeditor/ckeditor5-vue2';
Vue.use(CKEditor)

组件引用

    <el-form-item label="产品详情" prop="productInfo"><Ckedit   v-model="form.productInfo"   :min-height="192"/></el-form-item>

这篇关于vue2 引入ckeditor富文本的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/949431

相关文章

前端如何通过nginx访问本地端口

《前端如何通过nginx访问本地端口》:本文主要介绍前端如何通过nginx访问本地端口的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、nginx安装1、下载(1)下载地址(2)系统选择(3)版本选择2、安装部署(1)解压(2)配置文件修改(3)启动(4)

HTML中meta标签的常见使用案例(示例详解)

《HTML中meta标签的常见使用案例(示例详解)》HTMLmeta标签用于提供文档元数据,涵盖字符编码、SEO优化、社交媒体集成、移动设备适配、浏览器控制及安全隐私设置,优化页面显示与搜索引擎索引... 目录html中meta标签的常见使用案例一、基础功能二、搜索引擎优化(seo)三、社交媒体集成四、移动

HTML input 标签示例详解

《HTMLinput标签示例详解》input标签主要用于接收用户的输入,随type属性值的不同,变换其具体功能,本文通过实例图文并茂的形式给大家介绍HTMLinput标签,感兴趣的朋友一... 目录通用属性输入框单行文本输入框 text密码输入框 password数字输入框 number电子邮件输入编程框

HTML img标签和超链接标签详细介绍

《HTMLimg标签和超链接标签详细介绍》:本文主要介绍了HTML中img标签的使用,包括src属性(指定图片路径)、相对/绝对路径区别、alt替代文本、title提示、宽高控制及边框设置等,详细内容请阅读本文,希望能对你有所帮助... 目录img 标签src 属性alt 属性title 属性width/h

CSS3打造的现代交互式登录界面详细实现过程

《CSS3打造的现代交互式登录界面详细实现过程》本文介绍CSS3和jQuery在登录界面设计中的应用,涵盖动画、选择器、自定义字体及盒模型技术,提升界面美观与交互性,同时优化性能和可访问性,感兴趣的朋... 目录1. css3用户登录界面设计概述1.1 用户界面设计的重要性1.2 CSS3的新特性与优势1.

HTML5 中的<button>标签用法和特征

《HTML5中的<button>标签用法和特征》在HTML5中,button标签用于定义一个可点击的按钮,它是创建交互式网页的重要元素之一,本文将深入解析HTML5中的button标签,详细介绍其属... 目录引言<button> 标签的基本用法<button> 标签的属性typevaluedisabled

HTML5实现的移动端购物车自动结算功能示例代码

《HTML5实现的移动端购物车自动结算功能示例代码》本文介绍HTML5实现移动端购物车自动结算,通过WebStorage、事件监听、DOM操作等技术,确保实时更新与数据同步,优化性能及无障碍性,提升用... 目录1. 移动端购物车自动结算概述2. 数据存储与状态保存机制2.1 浏览器端的数据存储方式2.1.

基于 HTML5 Canvas 实现图片旋转与下载功能(完整代码展示)

《基于HTML5Canvas实现图片旋转与下载功能(完整代码展示)》本文将深入剖析一段基于HTML5Canvas的代码,该代码实现了图片的旋转(90度和180度)以及旋转后图片的下载... 目录一、引言二、html 结构分析三、css 样式分析四、JavaScript 功能实现一、引言在 Web 开发中,

Python中图片与PDF识别文本(OCR)的全面指南

《Python中图片与PDF识别文本(OCR)的全面指南》在数据爆炸时代,80%的企业数据以非结构化形式存在,其中PDF和图像是最主要的载体,本文将深入探索Python中OCR技术如何将这些数字纸张转... 目录一、OCR技术核心原理二、python图像识别四大工具库1. Pytesseract - 经典O

CSS place-items: center解析与用法详解

《CSSplace-items:center解析与用法详解》place-items:center;是一个强大的CSS简写属性,用于同时控制网格(Grid)和弹性盒(Flexbox)... place-items: center; 是一个强大的 css 简写属性,用于同时控制 网格(Grid) 和 弹性盒(F