Problem: Wechat applet rich-text rich text image exceeds the screen width
text data
Effect before change
Solution
Use regular rules to define the class of the img tag in the data or directly write the style
and then modify the data in the js file
data.content.replace(/\<img/gi, '<img style="max-width:100%;height:auto" ') //正则替换
or
that.setData({
content: res.data.content.replace(/\<img/gi, '<img style="max-width:100%;height:auto"')
})
或
that.setData({
content: res.data.contents.replace('<img ', '<img style="max-width:100%;height:auto"')
})
final effect