Skip to content

微信小程序父组件向子组件传递函数,执行了但是还是报错(h5可以运行) #2096

@JokerLoLgrey

Description

@JokerLoLgrey

问题描述
微信小程序父组件向子组件传递函数,执行了但是还是报错

复现步骤
1.首先我先封装了一些tabBar组件,代码如下

import Taro from '@tarojs/taro-h5';
import { AtTabBar } from 'taro-ui';
export default class Index extends Taro.Component {
  constructor() {
    super(...arguments);
    this.state = {
      current: 0
    };
  }
  handleClick(value) {
    this.setState({
      current: value
    });
    console.log(this.props);
    this.props.onCurrentPage(value);
  }
  render() {
    return <AtTabBar
      selectedColor="#212121"
      color="#BDBDBD"
      fixed={this.props.fixed}
      tabList={this.props.tabList}
      onClick={this.handleClick.bind(this)}
      current={this.state.current} />;
  }
}

2.然后我在某个页面使用了这个组件

// 这是父组件的函数
currentPage(value) {
    this.setState({
      currentPageShow: value
    });
  }
// 这个是调用这个组件
<TabBar tabList={tabList} fixed={fixed} onCurrentPage={this.currentPage.bind(this)} />

期望行为
微信小程序和h5一样能够完美运行

报错信息
这是报错信息
image
只执行了部分代码(页面没有切换)
image
image
image

系统信息
image

  • 报错平台 [weapp]

补充信息

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions