Taro中子组件调用父组件方法的问题



  • 父组件定义方法:

    type PageStateProps = {
    	OrderStore: {
    		getOrders: Function;
    		orders: Array<any>;
    		onAcceipt: Function;
    		confirmModalState: boolean;
    	};
    	onAcceptOrder: Function;
    };
    
    onAcceptOrder() {
      console.log(this);
    }
    
    {orders.map((item) => {
       return <OrderItem orderItem={item} key={item.workOrderId} onAcceptOrder={this.onAcceptOrder} />;
    })}
    };
    

    子组件中

    type PageStateProps = {
    	orderItem: {
    		workOrderId: string;
    		workOrderNo: string;
    		content: string;
    		createTime: string;
    		workOrderStatus: number;
    		createUserName: string;
    		acceptUserName: string;
    		productName: string;
    		productClassificationName: string;
    	};
    	onAcceptOrder: Function;
    
    
    
    onAcceptOrder = () => {
       console.log(this);
      this.props.onAcceptOrder();
    };
    
    <AtButton className='btn-accept' onClick={this.onAcceptOrder}>接单</AtButton>
    

    点击"接单"按钮以后会报this.props.onAcceptOrder is not a function,打印this.props中也没有onAcceptOrder这个方法


登录后回复