taro小程序展示富文本

在微信小程序下会用到wxParse这个东西来达到html转换wxml的效果,

taro小程序官方也给出了示例,地址

这里封装成自己的组件:

1import Taro, { Component } from "@tarojs/taro" 2import { View } from "@tarojs/components" 3import WxParse from '../../utils/wxParse/wxParse.js' 4import "../../utils/wxParse/wxParse.scss" 5 6export default class ParseComponent extends Component { 7 componentDidMount() {} 8 defaultProps = { 9 mark: "" 10 } 11 render() { 12 13 if (this.props.mark) { 14 let domText = this.props.mark 15 WxParse.wxParse("domText", "html", domText, this.$scope, 5); 16 } 17 return ( 18 <View> 19 {process.env.TARO_ENV === "weapp" ? ( 20 <View> 21 <import src='../../utils/wxParse/wxParse.wxml' /> 22 <template is='wxParse' data='{{wxParseData:domText.nodes}}' 23 /> 24 </View> 25 ) : ( 26 <View>只在小程序里支持</View> 27 )} 28 </View> 29 ); 30 } 31}

另外,转化之后的图片地址是相对地址,在小程序中是无法显示的,所以需要到html2json.js文件中加上图片的域名地址:

1//对img添加额外数据 2 if (node.tag === 'img') { 3 node.imgIndex = results.images.length; 4 var imgUrl = '域名地址' + node.attr.src; 5 if (imgUrl[0] == '') { 6 imgUrl.splice(0, 1); 7 } 8 imgUrl = wxDiscode.urlToHttpUrl(imgUrl, __placeImgeUrlHttps); 9 node.attr.src = imgUrl; 10 node.from = bindName; 11 results.images.push(node); 12 results.imageUrls.push(imgUrl); 13 }
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

微信小程序new Date()转换时间异常问题

微信小程序苹果手机页面上显示时间异常,安卓机正常问题image(https://imghelloworld.osscnbeijing.aliyuncs.com/imgs/b691e1230e2f15efbd81fe11ef734d4f.png)错误代码vardate'2021030617:00:00'vardateT

Taro小程序自定义顶部导航栏

微信自带的顶部导航栏是无法支持自定义icon和增加元素的,在开发小程序的时候自带的根本满足不了需求,分享一个封装好的组件,支持自定义icon、扩展dom,适配安卓、ios、h5,全面屏。我用的是京东的Taro多端编译框架写的小程序,原生的也可以适用,用到的微信/taro的api做调整就行,实现效果如下。!在这里插入图片描述(https://i

Taro_Mall 是一款多端开源在线商城小程序.

介绍Taro\_Mall(https://www.oschina.net/action/GoToLink?urlhttps%3A%2F%2Fgithub.com%2Fjiechud%2Ftaromall)是一款多端开源在线商城应用程序,后台是基于litemall基础上进行开发,前端采用Taro框架编写,现已全部完成小程序和h5移动端,后续会