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

小程序富文本图片大小问题

文章目录

    • 概要
    • uniapp小程序情况
    • 解决方法及完整示例

概要

在小程序使用富文本或者在nuiapp(小程序的)使用富文本都会转为

<rich-text nodes="<p class="p class">内容</p>></rich-text>

如果是这种情况的话在css里面就使用不了穿透样式了

/deep/{}

uniapp小程序情况

pc:小程序里面的v-html里面什么东西东不能有,包括注释,否则会报错

<view class="dowm"><view class="" v-html="ggDetailForm.msgContent"></view>
</view>

用uniapp写小程序在里面会自动转为

<rich-text nodes="<p class="p class">内容</p>></rich-text>

解决方法及完整示例

使用正则来修改富文本图片样式

	function formatRichText(html){console.log(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(/<p>/gi, '<p class="p_class">').replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');return match;});newContent = newContent.replace(/<br[^>]*\/>/gi, "");newContent = newContent.replace(/<a>/gi, '<a class="p_class "');newContent = newContent.replace(/<li>/gi, '<li class="p_class "');newContent = newContent.replace(/\<p/gi, '<p class="p_class "');newContent = newContent.replace(/\<span/gi, '<span class="p_class "');newContent = newContent.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block;margin-top:0;margin-bottom:0;"');return newContent;}export default {data() {return {formatRichText:formatRichText,}},methods: {ggDetail(id) {let obj = {id: id,}let that = thisuni.$u.http.get('接口', {params: obj,}).then(res => {if (res.success) {that.ggDetailForm = res.resultif(that.ggDetailForm.content){that.ggDetailForm.content = that.formatRichText(that.ggDetailForm.content)}}})},},}
http://www.lryc.cn/news/234083.html

相关文章:

  • Diagrams——制作短小精悍的流程图
  • Elasticsearch基础条件查询
  • 【SAP-ABAP】SAP与外围系统对接方式
  • 云计算的发展趋势
  • 国民技术Cortex-M0系列单片机IAP升级
  • Pycharm中添加Python库指南
  • Oracle OCP / MySQL OCP认证容易通过吗
  • flutter web 中嵌入一个html
  • 使用Spark SQL读取阿里云OSS的数据
  • 【0235】修改私有内存(private memory)中的MyBEEntry时,st_changecount值前后变化
  • Linux学习命令之source
  • 2342. 数位和相等数对的最大和
  • FISCO BCOS 3.0【01】搭建第一个区块链网络
  • UE4动作游戏实例RPG Action解析四:装备系统
  • AIGC之Stable Diffusion
  • PHP接收并处理请求中携带的xml格式的信息
  • 信息安全相关标准
  • Python入门学习篇(一)——注释变量输入输出
  • 基于单片机智能液位水位监测控制系统设计
  • iOS 添加震动效果
  • 合并word中参考文献-(Endnote生成)
  • linux(centos7)常用命令 开启关闭防火墙
  • 数据结构与算法面试题——C++
  • 数字音频工作站FL Studio21.1中文版本如何下载?
  • Linux 无名管道实现文件复制
  • 【机器学习】 逻辑回归算法:原理、精确率、召回率、实例应用(癌症病例预测)
  • 算法萌新闯力扣:存在重复元素II
  • 《洛谷深入浅出基础篇》——P3405 citis and state ——哈希表
  • 在QGIS中加载显示3DTiles数据
  • HBase学习笔记(3)—— HBase整合Phoenix