首页 > 其他分享 >富文本编辑器

富文本编辑器

时间:2023-02-07 16:11:05浏览次数:30  
标签:flex 文本编辑 default type editor text border

<template>
<div class="editorWrap" :style="cssVars">
<Toolbar v-if="showToolbar"
style="border-bottom: 1px solid #ccc"
:editor="editor"
:defaultConfig="toolbarConfig"
:mode="mode"
/>
<div :class="reviewStyle==1?'reviewBox':'contentBox'" :style="noBorder==1?'border:none':''">
<div class="editorBox">
<Editor v-if="showEditor"
style="overflow-y: hidden;" :style="{'min-height':`${editorHeight - 2}px`}"
:defaultConfig="editorConfig"
:mode="mode"
@onCreated="onCreated"
@input="changeText"
@onBlur="changeBlur"
/>
</div>
<!--富文本编辑器内插槽-->
<div class="slotBox">
<slot name="handle">

</slot>
</div>
</div>
<!--富文本编辑器右侧插槽-->
<div class="slotBox">
<slot name="handleRight">

</slot>
</div>
</div>
</template>

<script>
import {Editor, Toolbar} from "@wangeditor/editor-for-vue";
import {DomEditor} from '@wangeditor/editor'

export default {
name: "MyEditor",
components: {Editor, Toolbar},
props: {
showToolbar: {
type: Boolean,
default: false
},
content: {
type: String,
default: '',
},
//限制最大输入字符,默认为0时标识不做输入限制
maxLength: {
type: Number,
default: 0
},
//编辑器高度
editorHeight: {
type: [String, Number],
default: 96
},
//文本框问题提示的向上偏移高度
placeholderTop:{
type: String,
default: '6',
},
//提示文字
placeholder:{
type: String,
default: '',
},
editorTag:{
type: String,
default: '',
},
//预览样式,有无背景色
reviewStyle:{
type:Number,
default:0
},
// 是否有边框
noBorder:{
type:Number,
default:0
},
onlyRead:{
type:[Number,String],
default:0
}
},
watch: {
content: {
handler(val) {
// this.html = val;
// console.log('接受到的富文本', this.editor)
},
immediate: true
}
},
data() {
return {
showEditor: false,//是否显示编辑器
editor: null,
toolbarConfig: {},
editorConfig: {},
mode: 'default', // or 'simple'

};
},
computed: {
cssVars() {
return {
"--minHeight": `${this.editorHeight}px`,
"--placeholderTop": `${this.placeholderTop}px`
}
}
},

methods: {
changeBlur(){
this.$emit('editorBlur',this.editorTag)
},
changeText(e) {
// console.log('触发',e)
this.$emit('update:content', e)
},
onCreated(editor) {
this.editor = Object.seal(editor) // 一定要用 Object.seal() ,否则会报错
this.editor.setHtml(this.content);//插入内容

},

},
mounted() {
if(this.placeholder) {
this.editorConfig.placeholder = this.placeholder;
}
if (this.maxLength > 0) {
this.editorConfig.maxLength = this.maxLength
}
if(this.onlyRead==1){
this.editorConfig.readOnly = true
}
this.$nextTick(() => {
this.showEditor = true;
})
},
beforeDestroy() {
const editor = this.editor;
if (editor == null) return;
editor.destroy(); // 组件销毁时,及时销毁 editor ,重要!!!
},
};
</script>

<style src="@wangeditor/editor/dist/css/style.css"></style>

<style scoped lang="less">

::v-deep {
.w-e-text-container [data-slate-editor] {
min-height: var(--minHeight);
}

.w-e-text-container [data-slate-editor] p {
margin: 4px 0;

}
}

.editorWrap {
display: flex;
//margin-bottom: 6px;

.contentBox {
flex: 1;

border: 1px solid #e5e5e5;
box-sizing: border-box;
border-radius: 4px;
position: relative;
display: flex;
overflow: hidden;

.editorBox {
overflow: hidden;
flex: 1;
word-break:break-all;
::v-deep {
.w-e-text-container {
}
.w-e-text-placeholder{
font-style: initial;

top: var(--placeholderTop);
}
}
}
}
.reviewBox{
flex: 1;
border: 1px solid #e5e5e5;
box-sizing: border-box;
border-radius: 4px;
position: relative;
display: flex;
overflow: hidden;

.editorBox {
overflow: hidden;
flex: 1;
word-break:break-all;


::v-deep {
.w-e-text-container {
background: rgba(255, 255, 255, .1);
padding:3px 3px 12px 3px;
}
.w-e-text-placeholder{
font-style: initial;

top: var(--placeholderTop);
}
}
}
}
}
</style>
====================================================================
<TopicEditor :key="index"
:content="`${index + 1}.[${topicType[item.type]}] ${item.content}`" :editorHeight="30"
:no-border="1" :onlyRead="1"
:reviewStyle="1"></TopicEditor>

标签:flex,文本编辑,default,type,editor,text,border
From: https://www.cnblogs.com/connie256/p/17098834.html

相关文章

  • 百度富文本编辑器ueditor上传图片宽度设置
    分两步1.ueditor的themes文件夹下有个iframe.css加入以下代码,设置样式,保存(原先的css文件是空的)img{max-width:330;/*图片自适应宽度,这里设置为宽330px,高度......
  • wangeditor富文本编辑和vue3
    官网:wangEditor  https://www.wangeditor.com/v5/为啥用这个富文本编辑器(我觉得官网写自己优势已经非常好了没有啥可补充的了) 文档特别的全和友好安装yarnadd......
  • 富文本编辑器 quill.js 开发(二): 光标和选区
    术语表首先我们需要知道一些术语,才能更好地理解,如果您已经了解,可以跳过这一段锚点(anchor)锚指的是一个选区的起始点(不同于HTML中的锚点链接)。当我们使用鼠标......
  • LINUX学习之文本编辑器VIM/VI(八)
    简介VI是Unix操作系统和类Unix操作系统中最通用的文本编辑器VIM编辑器是从VI发展出来的一个性能更强大的文本编辑器。可以主动的以字体颜色辨别语法的正确性,方便......
  • linux-sed-文本编辑命令
    Md2Allexportdocumentsed命令详解简介sed是一种在线编辑器,它一次处理一行内容。处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(patternspace),接着用s......
  • 图片验证码,发送邮箱,富文本编辑器
    @目录图片验证码1、安装2、设置3、建立表单4、实现邮件发送1、settings.py配置2、发送邮件富文本编辑器1、安装2、settings.py设置3、实现图片验证码1、安装pipinstall......
  • 推荐几个非常不错的富文本编辑器
    1、wangEditor——基于javascript和css开发的Web富文本编辑器,轻量、简洁、界面美观、易用、开源免费。界面截图:官网地址   2、TinyMCE——TinyMCE是一个轻量级......
  • 富文本编辑器 种类,下载官网等介绍
    富文本编辑器   富文本编辑器(RichTextEditor,RTE)是一种可内嵌于浏览器,所见即所得的文本编辑器。它提供类似于OfficeWord的编辑功能,方便那些不太懂HTML用户使......
  • 富文本编辑器(KindEditor)
    目录富文本编辑器文章内容区使用富文本编辑器富文本编辑器上传图片问题富文本编辑器文章内容区使用富文本编辑器KindEditor是一套开源的在线HTML编辑器,主要用于让用......
  • NOI2003 文本编辑器 题解
    \STL大法好/正规解法块状链表,这里采取的是黑科技解法。rope是扩展STL库中的一个数据结构——可持久化平衡树,相比较set,它更适合区间插入和删除。这里用来解此题,就显得十......