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 (
      
 
        


        
                      
            
          
          
            
          
          
            
          
          
            
          
        

      

    )
  }
}

  • 子组件 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 (
      
        
          
            金额:23.5 元 {this.props.aaa}
            
              点我支付
            
          
        
      
    );
  }
}
export default Clist;

你可能感兴趣的:(微信小程序)