Taro: onClick监听函数的传值变了?

Created on 6 Mar 2019  ·  14Comments  ·  Source: NervJS/taro

为什么之前的onClick监听函数 可以 这样传值onClick={this.getValue.bind(this,value)} 就可以得到value 的值, 但是现在要在函数里 这样e.currentTarget.dataset.eTapAA 才能得到value的值?

question

Most helpful comment

CLI 和依赖都升级到最新版后试试

All 14 comments

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

CLI 和依赖都升级到最新版后试试

Hello~

您的问题楼上已经有了确切的回答,如果没有更多的问题这个 issue 将在 15 天后被自动关闭。

如果您在这 15 天中更新更多信息自动关闭的流程会自动取消,如有其他问题也可以发起新的 Issue。

Good luck and happy coding~

同样遇到这个问题,onClick传参只能拿到一个事件参数,其他都是undefined

我也遇到了类似的问题:

  1. 打包微信小程序后,使用onConfirm传递给子组件的()=>{}箭头函数子组件无法获得并调用
  2. 打包swan百度小程序后,找不到props传递给子组件confirm事件函数
    图片

  3. 代码地址:
    https://github.com/BDFE/taro-typescript/blob/master/src/components/wraper/index.tsx

我也遇到了类似的问题:

  1. 打包微信小程序后,使用onConfirm传递给子组件的()=>{}箭头函数子组件无法获得并调用
  2. 打包swan百度小程序后,找不到props传递给子组件confirm事件函数
    图片
  3. 代码地址:
    https://github.com/BDFE/taro-typescript/blob/master/src/components/wraper/index.tsx

JSX用箭头函数会有问题,试试直接用onConfirm={this.confirmLoc}来调用看看 @danieltao1993

我感觉是我更新taro cli 之后出现的问题 现在版本 👽 Taro v1.2.15;

image

暂时只能这样。
支付宝要去 e.currentTarget.dataset.eOnTapAA 这里面拿值
小程序要去 e.currentTarget.dataset.eTapAA 这里面拿值

@soymikey CLI 和依赖版本保持一致。1.2.15 事件是正确的,不存在取不到参数的情况。

@danieltao1993 @AKACC 同样地 CLI 和依赖都升级最新版后试试,我在 1.2.17 尝试传箭头函数是正常的。

// 父组件
import Taro, { Component } from '@tarojs/taro'
import { View } from '@tarojs/components'
import Child from '../../components/child/child'

export default class PageView extends Component {

  handleClick () {
    console.log('handleClick args: ', ...arguments)
  }

  render() {
    return (
      <View>
        <Child onClick={(a, b, e) => {
          console.log('in: ', a, b, e)
          this.handleClick(a, b, e)
        }}
        />
      </View>
    )
  }
}
// 子组件
import Taro, { Component } from '@tarojs/taro'
import { View } from '@tarojs/components'

import './child.scss'

export default class Child extends Component {
  handlerClick () {
    console.log('on fn: ', this.props.onClick)
    console.log(this.props.onClick(...arguments))
  }

  render() {
    return (
      <View>
        <View
          style='border: 1px solid blue;color: blue;'
          onClick={this.handlerClick.bind(this, 1, 2)}
        >
          Button 1
        </View>
      </View>
    )
  }
}

更新了cli 和项目依赖 到1.2.17 , 可以了

图片
图片

这样在百度小程序里,怎么都拿不到props传入的函数

@danieltao1993 不要打印,直接调用即可

@Chen-jj
图片
父组件传入的showPanel是TRUE,但是当前组件setState之后有时候会变成false,不知道是不是setState有问题
图片

@danieltao1993 debug指南

Was this page helpful?
0 / 5 - 0 ratings