uni vue 替换接口 v-html的图片
导读:formatRichText (html { let newContent= html.replace(/<img[^>]*>/gi,function(match,capture { match...
formatRichText (html) { let newContent= html.replace(/img[^> ]*> /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(/br[^> ]*\/> /gi, ''); newContent = newContent.replace(/\img/gi, 'img style="max-width:100%; height:auto; display:inline-block; margin:10rpx auto; "'); return newContent; }
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: uni vue 替换接口 v-html的图片
本文地址: https://pptw.com/jishu/294144.html