在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)">

使用上面的这种方法,就可以了

posted @ 2018-10-17 10:18  zhaobao1830  阅读(4453)  评论(1编辑  收藏  举报