uniapp编译微信小程序富文本rich

编程入门 行业动态 更新时间:2024-10-13 14:23:58

uniapp编译微信小程序富<a href=https://www.elefans.com/category/jswz/34/1771357.html style=文本rich"/>

uniapp编译微信小程序富文本rich

				this.detail.contents = this.detail.contents.replace(/\<img/gi, '<img style="display:block;max-width:90%;height:auto;border:2px solid #eee;box-shadow:5px 5px 5px rgba(100,100,100,0.8);margin-bottom:10px;text-align:center;" ');

开始采用这个replace方法,编译后h5中生效,微信小程序中不生效

详细查看代码,是因为在后台增加文章的时候,富文本编辑器自动给图片设置了宽度,导致在小程序中的替换虽然成功了,但是不生效

修改思路:先把rich-text中的style属性替换掉,然后再替换想要的样式,也就是通过两次replace实现,代码如下

this.detail.contents = this.detail.contents
//这里把img里面的style替换成空
.replace(/(style="(.*?)")|(width="(.*?)")|(height="(.*?)")/ig, '')
.replace(/\<img/gi, '<img style="display:block;max-width:90%;height:auto;border:2px solid #eee;box-shadow:5px 5px 5px rgba(100,100,100,0.8);margin-bottom:10px;text-align:center;" ');

好了,预览小程序,生效了,仅供参考

更多推荐

uniapp编译微信小程序富文本rich

本文发布于:2023-12-03 10:38:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1654424.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本   程序   uniapp   微信小   rich

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!