uniapp使用rich-text,對后台傳入數據進行處理


<rich-text class="content" :nodes="data.content | formatRichText"></rich-text>

過濾器

filters: {
            formatRichText(html) { //控制小程序中圖片大小
                let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
                    match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
                    match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
                    match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
                    return match;
                });
                newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
                    match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
                    return match;
                });
                // newContent = newContent.replace(/<br[^>]*\/>/gi, '');
                newContent = newContent.replace(/\<img/gi,
                    '<img style="max-width:90%;height:auto;display:inline-block;margin:10rpx auto;"');
                // newContent = newContent.replace(/<br[^>]*\/>/gi, '');
                // newContent = newContent.replace(/<td[^<>]*>/ig, '<td style="padding:0px;height:auto;word-break:break-all;border:1px;">');
                // newContent = newContent.replace(/<td[^<>]*>\s*?<p>/ig, '<td>');
                newContent = newContent.replace(/<table[^>]*>/gi, '<table cellpadding="0" cellspacing="0" max-width="100%" border="1" style="font-size:12px;max-width:100%; text-align:left;text-indent: 0em;line-height:12px;">'); 
                return newContent;
            }
        },

 

 

如果使用uParse,過濾器中的內容有的不能用


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM