在网上找到了个很好的方法,原文出自:
不用正则,写了个方法建了个div,把html片段放入div,然后再从div里取到纯文本,简直太赞,分享分享~
htmlToText(htmlStr) {
let theConvertDiv = document.createElement("div")
theConvertDiv.innerHTML = htmlStr
return theConvertDiv.textContent || theConvertDiv.innerText || ""
}