美文网首页vue、javascript
vue 中 v-html 通过正则表达式清除富文本标签中的sty

vue 中 v-html 通过正则表达式清除富文本标签中的sty

作者: 源大侠 | 来源:发表于2021-03-04 10:22 被阅读0次
<div id="details-article" v-html="removeHtmlStyle(detailsData.content)"></div>
 removeHtmlStyle(html) {
      let rel = /style\s*?=\s*?([‘"])[\s\S]*?\1/g;
      let newHtml = "";
      if (html) {
        newHtml = html.replace(rel, "");
      }
      // 清除类名
      // let relClass = /class\s*?=\s*?([‘"])[\s\S]*?\1/g;
      // let newClassHtml = "";
      // if (newHtml) {
      //   newClassHtml = newHtml.replace(relClass, "");
      // }
      return newHtml;
    },

相关文章

网友评论

    本文标题:vue 中 v-html 通过正则表达式清除富文本标签中的sty

    本文链接:https://www.haomeiwen.com/subject/uowhqltx.html