在富文本编辑器编辑的内容调用后端的接口保存再返回的数据带标签

场景:在前端的富文本编辑器编辑内容后,调用保存接口,保存成功后返回给前端的是带标签的文本

处理前:

处理后:
如何处理:这里的处理用到了正则

ToText(htmls) {//我这边是用到的elementui的table表格,对数组的content(保存的富文本编辑器的编辑内容)字段进行处理,所以把这个数组作为参数
      for (var i = 0; i < htmls.length; i++) {
        console.log(htmls[i].content, 'before-------')//打印处理前的数据
        let s = htmls[i].content.replace(/<(style|script|iframe)[^>]*?>[\s\S]+?<\/\1\s*>/gi, '').replace(/<[^>]+?>/g, '').replace(/\s+/g, ' ').replace(/ /g, ' ').replace(/>/g, ' ')
        htmls[i].content = s//处理好后重新赋值给这个数组
        console.log(htmls[i].content, 'after---------')
      }
    },

 亲测有效,大家快试试吧!

 

Guess you like

Origin blog.csdn.net/qq_45791799/article/details/120086577