rich-text代码:
<rich-text class="richtext" :nodes="detail | formatRichText" type = node></rich-text>
//利用过滤器来进行过滤
filters:{
formatRichText(html) { //控制小程序中图片大小
let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
console.log(match.search(/style=/gi));
if(match.search(/style=/gi) == -1){
match = match.replace(/\<img/gi,'<img style=""');
}
return match;
});
newContent = newContent.replace(/style="/gi, '$& max-width:100% !important; ');
newContent = newContent.replace(/<br[^>]*\/>/gi, '');
return newContent;
}
}
这是刚刚遇到的小程序富文本的问题,在这里记录一下,找到的这个办法也是别人提供的。