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

2021年2月18日08:50:38 发表评论
微信搜一搜 ts小陈
  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图片自适应结束

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

小陈号卡
ts小陈

发表评论(不允许含有网址!)

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

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