项目中遇到这样的需求,后端返回的是字符串,在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 newHtml8 }
1
使用上面的这种方法,就可以了