vue +element 实现富文本编辑器

富文本编辑器

官网地址: https://www.wangeditor.com/

html代码

<el-form-item label="正文">
        <div class="normal" id="contect_text">
        </div>
      </el-form-item>

js代码 在mounted里编写

	  mounted() {

const editor = new E(".normal");
editor.config.showFullScreen = false;
editor.config.pasteIgnoreImg = true;
editor.config.uploadFileName = 'file';
editor.config.uploadImgServer = ' http://192.168.1.1/upload/LABFILE/PORTAL/PortalAnnexFile';

editor.config.excludeMenus = ["emoticon", "video", "todo"];

editor.config.onblur = function (newHtml) {
  console.log("onblur", newHtml.replace(/<[^>]+>/g, "").replace(/(&nbsp;)/g, "")); // 获取最新的 html 内容
};
var _this = this;
editor.config.onchange = function (newHtml) {
  // _this.fuwenben = newHtml.replace(/<[^>]+>/g, "").replace(/(&nbsp;)/g, "");
  _this.fuwenben = newHtml;

  console.log(
    "change 之后最新的 html",
    newHtml.replace(/<[^>]+>/g, "").replace(/(&nbsp;)/g, "")
  );
};

editor.create();

**//到此结束**

 if (sessionStorage.getItem("edit_key") == null) {
      this.edit_list;
    }
     else {
      this.edit_list = JSON.parse(sessionStorage.getItem("edit_key"));
      console.log(this.edit_list);
      
      this.ruleForm.headline = this.edit_list.title
      this.ruleForm.author = this.edit_list.author
      
      // 点击编辑把数据带过来让用户编辑
      editor.txt.html(this.edit_list.sourceText) 
      
      this.imageUrl = this.edit_list.photoByteStream
      this.ruleForm.value = this.edit_list.noticeType
    }
     
  },

在这里插入图片描述

渲染问题

//标签也渲染v-text
<p @click="newwindow(item)" v-text="item.content">
        </p>
    /解析标签v-html

js

 // 拿到后端数据遍历
 res.data.root.forEach(function(e) {
 //下边重新赋一个变量备份一份
           e.sourceText = e.content
           //去掉标签和空格的正则
          e.content = e.content.replace(/<[^>]+>/g, "").replace(/(&nbsp;)/g, "")
          //this.$set 引起视图更新
          e = Object.assign([], e)
           console.log(e)
        })

增加一个小知识文字超过两行或三行就显示省略号

<div class="p1>  增加一个小知识文字超过两行或三行就显示省略号    </div>
.p1{
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值