Taro微信小程序可以用wxParse来达到html转换wxml的效果:https://github.com/NervJS/taro-components-test/blob/master/src/pages/wxParse/wxParse.js import Taro, { Component } from '@tarojs/taro' import { View, Text, Image, Button } from '@tarojs/components' import WxParse from '../../wxParse/wxParse' import "../../wxParse/wxParse.wxss"; class Home extends Component { constructor() { super(...arguments); this.state = ({ }) } config = { navigationBarTitleText: '首页' } componentWillMount() { } componentDidMount() { const article = '<div style="color: red">我是HTML代码</div><h2>标题2</h2><img src="http://192.168.122.142:80/public/1904/26/public-1904-26-c15d9fb7-0ad5-40a9-b845-6d085d6c0f30.jpg">' WxParse.wxParse('article', 'html', article, this.$scope, 5) } render() { return ( <View className="home"> <import src='../../wxParse/wxParse.wxml' /> <template is='wxParse' data='{{wxParseData:article.nodes}}'/> </View> ) } } export default Home
|
请发表评论