当前位置: 首页 > news >正文

uniapp使用v-html调用接口,富文本图片 视频自适应大小

前端获取到后台数据 不做处理 就会出现下面问题 图片 视频超出视图显示不全

请添加图片描述
处理

//info 是富文本
<view v-if='info' v-html='replaceWhite(info)'></view>

调用下面方法

replaceWhite(html) { // 处理富文本默认图片,视频大小let newContent = html.replace(/<video[^>]*>/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;}).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(/\<video/gi,'<video style="max-width:100%;height:auto;display:inline-block;margin:10rpx auto;"').replace(/\<img/gi,'<img style="max-width:100%;height:auto;display:inline-block;margin:10rpx auto;"');return newContent;},

参考大佬

感觉文章好的话记得点个心心和关注和收藏,有错的地方麻烦指正一下,如果需要转载,请标明出处,多谢!!!

http://www.lryc.cn/news/259155.html

相关文章:

  • 安卓MediaRecorder(2)录制源码分析
  • MySql数据库全量备份脚本
  • windows10下jdk安装
  • Centos7防火墙及端口开启
  • vue开发,axios网络请求框架基本用法和封装
  • 对比SPI、UART、I2C通信的区别与应用
  • CentOS7安装MySQL8.0
  • 【Go<—>Java】gRPC测试注意事项
  • java面试题整合
  • 2023年12月7日:QT实现登陆界面
  • 常用的测试用例大全
  • 《python每天一小段》--12 数据可视化《1》
  • 分类预测 | Matlab实现HPO-GRU【23年新算法】基于猎食者优化算法优化门控循环单元的数据分类预测
  • 【Pytorch】学习记录分享2——Tensor基础,数据类型,及其多种创建方式
  • 实验7:索引和视图定义
  • Source Tree回滚 重置 贮藏操作
  • Android13 不能静态注册的几个广播
  • 吴恩达深度学习L2W1作业1
  • uniapp原生插件之安卓app添加到其他应用打开原生插件
  • scala编码
  • 智慧路灯杆如何实现雪天道路安全监测
  • C语言指针基础题(二)
  • 物奇平台MIC配置与音频通路关系
  • 外包干了3年,技术退步太明显了。。。。。
  • 阶段十-java新特性
  • win10重装系统历程
  • 【知识积累】深度度量学习综述
  • webrtc网之sip转webrtc
  • 【Spring】依赖注入之属性注入详解
  • 6-tornado配置文件的使用(命令行解析、文件设置)