uniapp微信小程序 rich-text不换行解决办法

uniapp yekong 5222℃

rich-text不自动换行,排查了一下 发现接口返回的内容带有pre标签。将pre标签过滤后就可以了。应该是特殊标签导致的不换行。


        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, '');
                //过滤pre标签
            newContent = newContent.replace(/<(\/)?pre[^>]*>/gi, '');
            return newContent;
        },
喜欢 (5)