taro 渲染富文本,多个富文本切换

1 篇文章 0 订阅

官网demo:

https://github.com/NervJS/taro-components-test/blob/master/src/pages/wxParse/wxParse.js

多个富文本切换,主要用到display:none,当显示的时候,重新生成富文本

import Taro, { Component } from "@tarojs/taro"
import { View } from "@tarojs/components"
import WxParse from "@/components/wxParse/wxParse"
import Tab from "@/components/productDetailTab"
import "./index.scss"

type PageOwnProps = {
  description: string,
  shoppingNotice: string
}

class productIntro extends Component<PageOwnProps> {
  state = {
    activeIndex: 0
  }
  static defaultProps = {
    description:'暂无数据',
    shoppingNotice:'暂无数据',
  }
  handleClick(active: number) {
    this.setState({
      activeIndex: active
    },()=>{
      if(active==0){
        WxParse.wxParse("description", "html", this.props.description, this.$scope, 0)
      }else {
        WxParse.wxParse("shoppingNotice", "html", this.props.shoppingNotice, this.$scope, 0)
      }
    })
  }

  componentDidMount() {
    WxParse.wxParse("description", "html", this.props.description, this.$scope, 0)
  }

  render() {
    const tabList: {active: number, name: string}[] = [
      { active: 0, name: '项目详情' },
      { active: 1, name: '购买须知' },
      { active: 2, name: '体验报告' }
    ]
    return (
      <View className='product-intro'>
        <import src='../../../components/wxParse/wxParse.wxml' />
        <Tab tabList={tabList}
             active={this.state.activeIndex}
             lineWidth={114}
             onChangeActive={this.handleClick}/>
        <View className={this.state.activeIndex===0?'product-intro__content':'product-intro__content hidden'}>
          <template is='wxParse' data='{{wxParseData:description.nodes}}'/>
        </View>
        <View className={this.state.activeIndex===1?'product-intro__content':'product-intro__content hidden'}>
          <template is='wxParse' data='{{wxParseData:shoppingNotice.nodes}}'/>
        </View>
        <View className={this.state.activeIndex===2?'product-intro__content':'product-intro__content hidden'}>
          暂无数据
        </View>
      </View>
    )
  }
}

export default productIntro

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值