小程序显示富文本,有两种方法,一种使用官方控件rich-text,一种使用第三方库mp-html
1、rich-text
文档:https://developers.weixin.qq.com/miniprogram/dev/component/rich-text.html
这种方法图片无法点击预览。
2、mp-html
主页:https://github.com/jin-yufeng/mp-html
将源码中对应平台的代码包(dist/platform)拷贝到 components 目录下,更名为 mp-html
在需要使用页面的 json 文件中添加
{
"usingComponents": {
"mp-html": "/components/mp-html/index"
}
}
调用方法:
<mp-html content="{{html}}" />
另一个问题,有时候,android和本地开发工具里能显示图片,但是在ios上无法查看图片。后来发现,是ios不能显示webp格式的图片。
把图片的格式改成png,jpg就好了。