第一种方法:接口里给img标签加样式(PHP)
$info['contents'] = str_replace("<img ", "<img style='max-width:100%;height:auto;'", $info['contents']);
第二种方法:小程序里给img标签加样式
that.setData({
//富文本内容
contents: res.data.contents.replace(/\<img/gi, '<img style="max-width:100%;height:auto"')
})
本文探讨了两种使微信小程序中rich-text组件内的图片实现自适应宽度的方法:一种是在后端PHP接口中为img标签添加样式,另一种是在小程序前端直接设置img标签样式。
1万+

被折叠的 条评论
为什么被折叠?



