rich-text富文本更改图片img大小
这是后台返回的富文本数据格式,注意看里面有一个空的style=“”,首先需要把style=""字段删除掉,然后再用replace方法加上样式,否则会不生效
// 假设htmlContent字段是后台返回的富文本字段
let str = htmlContent.replaceAll('style=""','') // 去掉style=""
const regex = new RegExp('img','gi')
str = str.replace(regex,`img style="max-width:100%;"`) // 加上自己所需要的样式
如果后台返回给前端的数据里面没有style=“”,就可以直接进行第二行代码