在v-html中,js 正則表達式清除字符串里的style屬性


項目中遇到這樣的需求,后端返回的是字符串,在vue用v-html顯示,里面有style樣式,要去除style

在v-html中使用filters,和平時的不一樣,推薦項目的方法,定義一個全局的過濾方法

1 Vue.prototype.removeHtmlStyle = function (html) {
2   var rel = /style\s*?=\s*?([‘"])[\s\S]*?\1/
3   var newHtml = ''
4   if (html) {
5     newHtml = html.replace(rel, '')
6   }
7   return newHtml
8 }
1 <div class="paragraph" v-html="removeHtmlStyle(articleContent.post_content)">

使用上面的這種方法,就可以了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM