解决小程序中的rich-text标签解析出来的图片大小

模拟请求接口

wx.request({
    
    
  url: 'https://api.it120.cc/small4/cms/news/detail',
  header: {
    
    
    'Content-Type': 'application/json'
  },
  success: function(res) {
    
    
       const CONTENT = res.data.data.content.replace(
          /\<img/gi,
          '<img style="width:100%;height:auto" '
        );
  }
  this.setData({
    
    
           CONTENT: CONTENT,
        });
})

重点代码是:replace( /\<img/gi, '<img style="width:100%;height:auto" ' );
#

页面渲染:

  <rich-text class="image" nodes="{
    
    { CONTENT }}"> </rich-text>

猜你喜欢

转载自blog.csdn.net/weixin_46174785/article/details/108914324