Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

小程序三方组件传参不支持函数 #11992

Open
WEN-JY opened this issue Jun 25, 2022 · 1 comment
Open

小程序三方组件传参不支持函数 #11992

WEN-JY opened this issue Jun 25, 2022 · 1 comment
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@WEN-JY
Copy link

WEN-JY commented Jun 25, 2022

相关平台

支付宝小程序

复现仓库

https://github.com/WEN-JY/taro-demo
小程序基础库: 1.25.7
使用框架: React

复现步骤

clone 仓库,安装依赖
启动:yarn dev:alipay
进入小程序调试

期望结果

期望能够给自定义组件custom-comp1传递函数作为参数,便于自定义原生组件内部回调父组件进行数据通信

实际结果

以on开头的参数被当做了事件,执行时出发eventHandle校验type失败报错,非on开头的函数原生组件内无法接收到传递的函数,为undefined

环境信息

Taro CLI 3.5.0-canary.1 environment info:
    System:
      OS: macOS 11.5
      Shell: 5.8 - /bin/zsh
    Binaries:
      Node: 16.13.1 - ~/.nvm/versions/node/v16.13.1/bin/node
      Yarn: 1.22.10 - /usr/local/bin/yarn
      npm: 8.1.2 - ~/.nvm/versions/node/v16.13.1/bin/npm
    npmPackages:
      @tarojs/components: 3.5.0-canary.1 => 3.5.0-canary.1 
      @tarojs/mini-runner: 3.5.0-canary.1 => 3.5.0-canary.1 
      @tarojs/react: 3.5.0-canary.1 => 3.5.0-canary.1 
      @tarojs/runtime: 3.5.0-canary.1 => 3.5.0-canary.1 
      @tarojs/taro: 3.5.0-canary.1 => 3.5.0-canary.1 
      @tarojs/webpack-runner: 3.5.0-canary.1 => 3.5.0-canary.1 
      babel-preset-taro: 3.5.0-canary.1 => 3.5.0-canary.1 
      eslint-config-taro: 3.5.0-canary.1 => 3.5.0-canary.1 
      react: ^17.0.0 => 17.0.2 

页面入口:

import { Component } from 'react'
import { View, Text } from '@tarojs/components'
import './index.scss'

export default class Index extends Component {
  handleCustomClick = (...args) => {
    console.log('child custom component clicked',...args)
  }
  render() {
    return (
      <View className='index'>
        {/* 三方原生组件 */}
        <custom-comp1
          onComponentClick={this.handleCustomClick}
          onComponentClick1={this.handleCustomClick}
          onComponentClick2={this.handleCustomClick}
          onComponentClick23={this.handleCustomClick}
          onComponentClick4={this.handleCustomClick}
          onComponentClick5={this.handleCustomClick}
          componentClick={this.handleCustomClick}
          someAttr='1'
        ></custom-comp1>
        <Text>Hello world!</Text>
        <view onTap={this.handleCustomClick}>内置原生组件</view>
      </View>
    )
  }
}

custom-comp:
image

报错信息:
以on开头的函数:
image
普通函数:
image

@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Jun 25, 2022
@Chen-jj
Copy link
Contributor

Chen-jj commented Jul 7, 2022

#11835

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
None yet
Development

No branches or pull requests

2 participants