从上面可以看到,从接口获得的图片尺寸过大,已经超出了屏幕
解决方法:可以通过‘>>>’ 属性穿透 的办法解决
1、css原生
<view class="lawintro">
<view class="text2">律所介绍</view>
<view class="text3">
<rich-text :nodes="detail.text_content"> </rich-text>//接口
</view>
</view>
//css 例如 修改text3富文本接口里面的图片
.text3>>>img {
width: 100%;
}
2、如果使用了scss
.text3{
::v-deep img {
width: 100%;
}
}
上面两种方法是针对浏览器的,修改微信小程序的方法如下(使用属性选择器,使用的属性为img的描述属性alt,<img src='...' alt='' id='123' />)
如果再解决不了,这样
<rich-text :nodes="format(要转换的参数)"></rich-text>
format(html) {
var GRT = [
// img 样式
['img', "max-width:100%;height:auto;"],
];
for (let i = 0; i < GRT.length; i++) {
html = html.replace(new RegExp('<' + GRT[i][0] + '>|<' + GRT[i][0] + ' (.*?)>', 'gi'), function(word) {
// 分析 dom 上是否带有 style=""
if (word.indexOf('style=') != -1) {
var regIn = new RegExp('<' + GRT[i][0] + '(.*?)style="(.*?)"(.*?)(/?)>', 'gi');
return word.replace(regIn, '<' + GRT[i][0] + '$1style="$2 ' + GRT[i][1] + '"$3$4>');
} else {
var regIn = new RegExp('<' + GRT[i][0] + '(.*?)(/?)>', 'gi');
return word.replace(regIn, '<' + GRT[i][0] + '$1 style="' + GRT[i][1] + '$2">');
}
});
}
return html;
},
效果:可以看到图片不会再溢出