富文本图片样式

在做项目的时候很多时候都会用到富文本,当后端把一段富文本格式的参数传给你可以使用<rich-text :nodes="value"></rich-text>来解析富文本,但是有的时候传过来的富文本中会出现图片,当我们把图片渲染到页面的时候发现图片并没有根据我们想要的方式渲染到页面上会出现下面的效果
在这里插入图片描述
可以看到图片的右方明显的溢出去了,那么想要修改图片的样式可以这样修改

this.aid = this.aid.replace(/<p([\s\w"=\/\.:;]+)((?:(style="[^"]+")))/ig, '<p')
						.replace(/<p>/ig, '<p style="font-size: 15px; line-height: 25px;">')
						.replace(/<img([\s\w"-=\/\.:;]+)((?:(height="[^"]+")))/ig, '<img$1')
						.replace(/<img([\s\w"-=\/\.:;]+)((?:(width="[^"]+")))/ig, '<img$1')
						.replace(/<img([\s\w"-=\/\.:;]+)((?:(style="[^"]+")))/ig, '<img$1')
						.replace(/<img([\s\w"-=\/\.:;]+)((?:(alt="[^"]+")))/ig, '<img$1')
						.replace(/<img([\s\w"-=\/\.:;]+)/ig, '<img style="width: 100%;" $1');

猜你喜欢

转载自blog.csdn.net/qq_49552046/article/details/120843279
今日推荐