uniapp 微信小程序富文本图片宽度自适应处理

uniapp yekong 110℃

js用方法将数据过滤一次进行渲染


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;
        },
喜欢 (1)