項目中遇到這樣的需求,后端返回的是字符串,在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)">
使用上面的這種方法,就可以了