Taro -- 微信小程序wxParse达到html转换wxml


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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM