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

相关文章

使用Vue-ECharts实现数据可视化图表功能

《使用Vue-ECharts实现数据可视化图表功能》在前端开发中,经常会遇到需要展示数据可视化的需求,比如柱状图、折线图、饼图等,这类需求不仅要求我们准确地将数据呈现出来,还需要兼顾美观与交互体验,所... 目录前言为什么选择 vue-ECharts?1. 基于 ECharts,功能强大2. 更符合 Vue

Vue中插槽slot的使用示例详解

《Vue中插槽slot的使用示例详解》:本文主要介绍Vue中插槽slot的使用示例详解,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录一、插槽是什么二、插槽分类2.1 匿名插槽2.2 具名插槽2.3 作用域插槽三、插槽的基本使用3.1 匿名插槽

springboot+vue项目怎么解决跨域问题详解

《springboot+vue项目怎么解决跨域问题详解》:本文主要介绍springboot+vue项目怎么解决跨域问题的相关资料,包括前端代理、后端全局配置CORS、注解配置和Nginx反向代理,... 目录1. 前端代理(开发环境推荐)2. 后端全局配置 CORS(生产环境推荐)3. 后端注解配置(按接口

Vue 2 项目中配置 Tailwind CSS 和 Font Awesome 的最佳实践举例

《Vue2项目中配置TailwindCSS和FontAwesome的最佳实践举例》:本文主要介绍Vue2项目中配置TailwindCSS和FontAwesome的最... 目录vue 2 项目中配置 Tailwind css 和 Font Awesome 的最佳实践一、Tailwind CSS 配置1. 安

CSS3 布局样式及其应用举例

《CSS3布局样式及其应用举例》CSS3的布局特性为前端开发者提供了无限可能,无论是Flexbox的一维布局还是Grid的二维布局,它们都能够帮助开发者以更清晰、简洁的方式实现复杂的网页布局,本文给... 目录深入探讨 css3 布局样式及其应用引言一、CSS布局的历史与发展1.1 早期布局的局限性1.2

使用animation.css库快速实现CSS3旋转动画效果

《使用animation.css库快速实现CSS3旋转动画效果》随着Web技术的不断发展,动画效果已经成为了网页设计中不可或缺的一部分,本文将深入探讨animation.css的工作原理,如何使用以及... 目录1. css3动画技术简介2. animation.css库介绍2.1 animation.cs

CSS引入方式和选择符的讲解和运用小结

《CSS引入方式和选择符的讲解和运用小结》CSS即层叠样式表,是一种用于描述网页文档(如HTML或XML)外观和格式的样式表语言,它主要用于将网页内容的呈现(外观)和结构(内容)分离,从而实现... 目录一、前言二、css 是什么三、CSS 引入方式1、行内样式2、内部样式表3、链入外部样式表四、CSS 选

使用雪花算法产生id导致前端精度缺失问题解决方案

《使用雪花算法产生id导致前端精度缺失问题解决方案》雪花算法由Twitter提出,设计目的是生成唯一的、递增的ID,下面:本文主要介绍使用雪花算法产生id导致前端精度缺失问题的解决方案,文中通过代... 目录一、问题根源二、解决方案1. 全局配置Jackson序列化规则2. 实体类必须使用Long封装类3.

Nginx部署React项目时重定向循环问题的解决方案

《Nginx部署React项目时重定向循环问题的解决方案》Nginx在处理React项目请求时出现重定向循环,通常是由于`try_files`配置错误或`root`路径配置不当导致的,本文给大家详细介... 目录问题原因1. try_files 配置错误2. root 路径错误解决方法1. 检查 try_f

在React聊天应用中实现图片上传功能

《在React聊天应用中实现图片上传功能》在现代聊天应用中,除了文字和表情,图片分享也是一个重要的功能,本文将详细介绍如何在基于React的聊天应用中实现图片上传和预览功能,感兴趣的小伙伴跟着小编一起... 目录技术栈实现步骤1. 消息组件改造2. 图片预览组件3. 聊天输入组件改造功能特点使用说明注意事项