前端获取到后台数据 不做处理 就会出现下面问题 图片 视频超出视图显示不全

处理

//info 是富文本

调用下面方法

replaceWhite(html) { // 处理富文本默认图片,视频大小

let newContent = html.replace(/]*>/gi, function(match, capture) {

match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');

match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');

match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');

return match;

}).replace(/]*>/gi, function(match, capture) {

match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');

match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');

match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');

return match;

});

newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {

match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi,

'max-width:100%;');

return match;

});

newContent = newContent.replace(/]*\/>/gi, '');

newContent = newContent.replace(/\

'

'uni-app 前端 v-html富文本视频适配 uniapp使用v-html调用接口,富文本图片 视频自适应大小  第1张

return newContent;

},

参考大佬

感觉文章好的话记得点个心心和关注和收藏,有错的地方麻烦指正一下,如果需要转载,请标明出处,多谢!!!

好文推荐

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: