• uniapp使用richtext,对后台传入数据进行处理


    <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(/[^;]+;/gi, 'max-100%;').replace(/[^;]+;/gi, 'max-100%;');
                        return match;
                    });
                    // newContent = newContent.replace(/<br[^>]*\/>/gi, '');
                    newContent = newContent.replace(/\<img/gi,
                        '<img style="max-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-100%; text-align:left;text-indent: 0em;line-height:12px;">'); 
                    return newContent;
                }
            },

    如果使用uParse,过滤器中的内容有的不能用

  • 相关阅读:
    让svn自动更新代码注释中的版本号
    前端开发利器F5
    当inlineblock和textindent遇到IE6,IE7
    DSL与函数式编程
    [译]当Node.js遇上WebMatrix 2
    《大道至简》的读后感
    深度学习之卷积神经网络之一
    ORACLE TRUNC()函数
    oracle rownum
    ORACLE 忽略已有重复值 创建唯一约束
  • 原文地址:https://www.cnblogs.com/brillant/p/16018056.html
Copyright © 2020-2023  润新知