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

    科技2022-07-12  139

    模拟请求接口

    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>
    Processed: 0.012, SQL: 8