Wechat applet rich-text rich text solves the problem that the picture exceeds the screen width

Problem: Wechat applet rich-text rich text image exceeds the screen width

text data

insert image description here

Effect before change

insert image description here
insert image description here
insert image description here

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

insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/hyqhyqhyqq/article/details/129798736
Recommended