小程序rich-text组件如何改变内部img图片样式的方法

2021年2月18日08:50:38 发表评论
广告也精彩
  1. //rich-text组件img图片自适应开始
  2. var data=res.data.body
  3. //.replace(/width: 553px; height: 270px;/g, 'max-width:100%;height:auto;display:block;') 指定图片尺寸替换样式
  4. .replace(/<p([\s\w"=\/\.:;]+)((?:(style="[^"]+")))/ig, '<p')
  5. .replace(/<p>/ig, '<p style="font-size: 15Px; line-height: 25Px;">')
  6. .replace(/<img([\s\w"-=\/\.:;]+)((?:(height="[^"]+")))/ig, '<img$1')
  7. .replace(/<img([\s\w"-=\/\.:;]+)((?:(width="[^"]+")))/ig, '<img$1')
  8. .replace(/<img([\s\w"-=\/\.:;]+)((?:(style="[^"]+")))/ig, '<img$1')
  9. .replace(/<img([\s\w"-=\/\.:;]+)((?:(alt="[^"]+")))/ig, '<img$1')
  10. .replace(/<img([\s\w"-=\/\.:;]+)/ig, '<img$1 style="max-width:100%;height:auto;display:block;"');
  11. res.data.body=data
  12. //rich-text组件img图片自适应结束

  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的微信公众号
  • 我的微信公众号扫一扫
  • weinxin
ts小陈

发表评论(请规范评论)--评论需审核

:?: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :cry: :mrgreen: :neutral: :razz:

已登录用户不需要填写以下内容