taro - 组件自定义事件方法传递

  • 父组件 Paylist
    直接上代码,就不分析了。
import Taro, { Component } from '@tarojs/taro'
import { View } from '@tarojs/components'
import { AtNavBar } from 'taro-ui'
import Clist from '../../components/pay/paylist/Clist.jsx'
import './paylist.scss'

export default class Paylist extends Component {

  componentWillMount() { }

  componentDidMount() { }

  componentWillUnmount() { }

  componentDidShow() { }

  componentDidHide() { }

  config = {
    navigationBarTitleText: ''
  }
  handleClick() {
    Taro.navigateBack()
  }
  btClickEvent = (e) =>{
     
    console.log('paylist btonclick 目标缴费编号>>'+e)
  }

  render() {
    return (
      <View style='background-color: #ffffff;'>
 
        <AtNavBar
          onClickRgIconSt={this.handleClick}
          onClickRgIconNd={this.handleClick}
          onClickLeftIcon={this.handleClick}
          color='#6190E8'
          title='待缴费列表'
          leftText='返回'
          fixed='true'
          leftIconType='chevron-left'
        />


        <View style='padding-top:30px'>
          <View className='paylist' >            
            <Clist aaa='QQ2' hisPayId='his11111' onPayClick={this.btClickEvent}></Clist>
          </View>
          <View className='paylist'>
            <Clist hisPayId='his12222'  onPayClick={this.btClickEvent}  ></Clist>
          </View>
          <View className='paylist'>
            <Clist></Clist>
          </View>
          <View className='paylist'>
            <Clist></Clist>
          </View>
        </View>

      </View>

    )
  }
}

  • 子组件 Clist
import Taro, { Component } from '@tarojs/taro';
import { View } from '@tarojs/components';
import { AtCard } from "taro-ui"
import { ClButton } from "mp-colorui";
import paytag from '../../../asset/images/base/paytag.png'
import './Clist.scss'

class Clist extends Component {
  constructor(props) {
    super(props);
    this.state = {
      hispayid: 0
    }

  }
  config = {
    navigationBarTitleText: ''
  }

  state = {}

  componentWillMount() { }
  componentDidMount() { }
  componentWillUnmount() { }
  componentDidShow() { }
  componentDidHide() { }
  componentDidCatchError() { }
  componentDidNotFound() { }
  goToPay() {
    try {
       this.props.onPayClick(this.state.hispayid) 
      }
    catch (e) { 
      console.log('处理父事件异常')
     }

  }
  render() {
    this.setState({
      hispayid: this.props.hisPayId
    })
    return (
      <View className='Clist'>
        <AtCard
          note='订单日期: 2020-3-26'
          extra='呼吸科'
          title={'编号:' + this.state.hispayid}
          thumb={paytag}
        >
          <View className='at-row at-row__justify--between'  >
            <View className='at-col at-col-9' style='font-size:18px'>金额:23.5 元 {this.props.aaa}</View>
            <View className='at-col at-col-3' onClick={this.goToPay}>
              <ClButton shape='round' bgColor='green' >点我支付</ClButton>
            </View>
          </View>
        </AtCard>
      </View>
    );
  }
}
export default Clist;
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

何浩翔

如果对你多帮助,请支持。感谢!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值