Skip to content

父组件向子组件传递函数,父组件不执行 #1475

@AllanChen

Description

@AllanChen

问题描述

父组件向子组件传递函数,父组件不执行

### 父组件
import Taro, { Component } from '@tarojs/taro'
import { View, Image, Picker,Text } from '@tarojs/components';
import PageOne from './PageOne'
export default class Consulations extends Component{
  constructor(props) {
    super(props);
    this.state = {
    };
  }
  onHandleFilpPage(){
    console.log("flip");
    this.setState({
      show:true
    })
  }

  render() {
    const {
        petSelect,
        petInfo    
      } = this.state;  
      console.log(this.props)
    return (
      <View className='consulations'>
        <Image src={bg} class="bg"></Image>   
        <View className='picker'>
            <Picker range={petInfo} rangeKey="name" onChange={this.onChange}>
              <Text className='pet-name'>{petSelect}</Text>
            </Picker>
        </View>         
            <PageOne onClick={this.onHandleFilpPage.bind(this)} />              
    </View>
    );}

### 子组件
import Taro, { Component } from '@tarojs/taro'
import { View, Picker,Text,Label,Input,Switch,Button } from '@tarojs/components';
import './index.less';

export default class PageOne extends Component{
    
  constructor(props) {
    super(props);
    this.state = {
      
    };
  }

 onClickHandler = () => {
        console.log('onClickHandler');        
        this.props.onHandleFilpPage()
  }

render() {
    return (
  <View>
<Text>hello</Text>
<Button onClick={this.onClickHandler}>hello</Button>
</View>
)}
}

期望行为
[父组件时间可以触发]

系统信息

  • 操作系统: [MacOS 10.13.5 (]
  • Taro 版本 [v0.0.73]
  • Node.js 版本 [v10.10.0]
  • 报错平台 [weapp]

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions