uniapp:富文本回显

一、使用uniapp官方的标签

rich-text:

会出现图片无法显示的问题,可以用以下方法来过滤处理

html 复制代码
<rich-text :nodes="question.title | formatRichHtml"></rich-text>
javascript 复制代码
        formatRichHtml(html) {
            if (!html) {
                return 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, '');
            newContent = newContent.replace(/background-color[\s:]+[^;]*;/gi, '');
            return newContent;
        }

二、使用 扩展插件

还有一些扩展的,比如音视频

mp-html:

官方文档:小程序富文本组件

组件属性

属性 类型 默认值 说明
container-style String 容器的样式(2.1.0+
content String 用于渲染的 html 字符串
copy-link Boolean true 是否允许外部链接被点击时自动复制
domain String 主域名(用于链接拼接)
error-img String 图片出错时的占位图链接
lazy-load Boolean false 是否开启图片懒加载
loading-img String 图片加载过程中的占位图链接
pause-video Boolean true 是否在播放一个视频时自动暂停其他视频
preview-img Boolean true 是否允许图片被点击时自动预览
scroll-table Boolean false 是否给每个表格添加一个滚动层使其能单独横向滚动
selectable Boolean false 是否开启文本长按复制
set-title Boolean true 是否将 title 标签的内容设置到页面标题
show-img-menu Boolean true 是否允许图片被长按时显示菜单
tag-style Object 设置标签的默认样式
use-anchor Boolean false 是否使用锚点链接

完~

相关推荐
行思理7 小时前
UniApp 打包配置 iOS的UniversalLinks
uni-app·universal link
雪芽蓝域zzs7 小时前
uni-app x 使用 UTS 语言使用 mixins
开发语言·javascript·uni-app
雪芽蓝域zzs8 小时前
uni-app x 中使用 UTS 语言实现兼容鸿蒙的加密
华为·uni-app·harmonyos
2501_915909069 小时前
苹果App Store上架全流程指南从注册到上线
android·ios·小程序·https·uni-app·iphone·webview
anyup1 天前
uni-app 全能日历组件,支持农历、酒店预订、打卡签到、价格日历多种场景
前端·前端框架·uni-app
优雅的大白鹅2 天前
创建uniapp小程序
小程序·uni-app
笨笨狗吞噬者3 天前
uni-app 运行时揭秘:styleIsolation 的转化
前端·微信小程序·uni-app
神の愛3 天前
JeecgBoot-Uniapp
uni-app
怀君3 天前
Uniapp——微信小程序Canvas层级过高问题解决
微信小程序·小程序·uni-app
阿凤214 天前
uniapp运行到app端怎么打开文件
android·前端·javascript·uni-app