解决使用v-html 转译富文本数据,标签还在的问题

282 阅读1分钟

按理说使用v-html转译富文本数据,html标签就没了,但有时候还是有

方法一

HTMLDecode(text) {
        var temp = document.createElement("div");
        temp.innerHTML = text;
        var output = temp.innerText || temp.textContent;
        temp = null;
        return output;
      },

方法二

HTMLDecode(str) {
        return str
          .replace(str ? /&(?!#?\w+;)/g : /&/g, '&')
          .replace(/&lt;/g, "<")
          .replace(/&gt;/g, ">")
          .replace(/&quot;/g, "\"")
          .replace(/&#39;/g, "\'");
      },