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

函数传参无法取到 #1820

Closed
hyyqcweb opened this issue Jan 5, 2019 · 9 comments
Closed

函数传参无法取到 #1820

hyyqcweb opened this issue Jan 5, 2019 · 9 comments

Comments

@hyyqcweb
Copy link

hyyqcweb commented Jan 5, 2019

问题描述
事件绑定传参, 取不到参数, 取到的是 arguments对象

复现步骤

handleClick = (item) => {
    console.log(item);
  };

render() {
    return (
      <View>
        {[1,2].map((t, r) => (
          <Button key={r} onClick={this.handleClick.bind(this, t)}>
            {t}
          </Button>
        ))}
      </View>
    )
  }

期望行为
可以正常的拿到事件函数的参数

报错信息
image

系统信息
image

  • 报错平台: weapp

补充信息
最新依赖:
image

@taro-bot
Copy link

taro-bot bot commented Jan 5, 2019

欢迎提交 Issue~

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

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

Good luck and happy coding~

@sadianliaoer
Copy link

我更新完,也需要上面的问题,

onClick={this.handleClick.bind(this, 1)} 

handleClick = (type) => {console.log(type)}

wx20190105-165811 2x

@hyyqcweb
Copy link
Author

hyyqcweb commented Jan 5, 2019

是的, 我什么方法都试了, 比如删除 node_modules , npm update, 还是取不到正常的值

@Chen-jj
Copy link
Contributor

Chen-jj commented Jan 8, 2019

@hyyqcweb @ZhiGang-Fang Taro 1.2.4 版本上尝试,没有问题,能正确取值。

你们的问题肯定是 CLI 和依赖版本不一致导致的,可以删掉 node_modules 后手动 npm install 试试。

import Taro, { Component } from '@tarojs/taro'
import { View } from '@tarojs/components'

export default class PageView extends Component {
  handleClick = (item) => {
    console.log(item)
  }

  render() {
    return (
      <View>
        {[1,2].map((t, r) => (
          <View key={r} onClick={this.handleClick.bind(this, t)}>
            {t}
          </View>
        ))}
      </View>
    )
  }
}

image

@wswax
Copy link

wswax commented Feb 20, 2019

这个问题怎么解决的呢?我用的taro版本是1.2.12

@hyyqcweb
Copy link
Author

@wswax 要么升级taro版本依赖(必须统一), 要么降级taro版本(我是降级处理了)

@wswax
Copy link

wswax commented Feb 20, 2019

@hyyqcweb 嗯我刚刚升级了。
目前是这样子,可以了。

Taro v1.2.13

Taro CLI 1.2.13 environment info:
System:
OS: macOS High Sierra 10.13.6
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 10.14.2 - /usr/local/bin/node
Yarn: 1.9.4 - /usr/local/bin/yarn
npm: 6.4.1 - /usr/local/bin/npm
npmPackages:
@tarojs/async-await: ^1.2.0 => 1.2.12
@tarojs/components: ^1.2.0 => 1.2.12
@tarojs/plugin-babel: ^1.2.0 => 1.2.12
@tarojs/plugin-csso: ^1.2.0 => 1.2.12
@tarojs/plugin-sass: ^1.2.0 => 1.2.12
@tarojs/plugin-uglifyjs: ^1.2.0 => 1.2.12
@tarojs/redux: ^1.2.0 => 1.2.12
@tarojs/redux-h5: ^1.2.0 => 1.2.12
@tarojs/router: ^1.2.0 => 1.2.12
@tarojs/taro: ^1.2.0 => 1.2.12
@tarojs/taro-alipay: ^1.2.0 => 1.2.12
@tarojs/taro-h5: ^1.2.0 => 1.2.12
@tarojs/taro-swan: ^1.2.0 => 1.2.12
@tarojs/taro-tt: ^1.2.0 => 1.2.12
@tarojs/taro-weapp: ^1.2.0 => 1.2.12
@tarojs/webpack-runner: ^1.2.0 => 1.2.12
eslint-config-taro: ^1.2.0 => 1.2.12
eslint-plugin-taro: ^1.2.0 => 1.2.12
nervjs: ^1.3.9 => 1.3.12

@Chen-jj
Copy link
Contributor

Chen-jj commented Feb 20, 2019

@wswax CLI 和依赖要保持一致,不然又可能出现其它问题。你现在分别是 1.2.13 和 1.2.12

@wswax
Copy link

wswax commented Feb 20, 2019

@Chen-jj 嗯,多谢提醒。
刚重新安装了一下。
Taro v1.2.13

Taro CLI 1.2.13 environment info:
System:
OS: macOS High Sierra 10.13.6
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 10.14.2 - /usr/local/bin/node
Yarn: 1.9.4 - /usr/local/bin/yarn
npm: 6.4.1 - /usr/local/bin/npm
npmPackages:
@tarojs/async-await: ^1.2.0 => 1.2.13
@tarojs/components: ^1.2.0 => 1.2.13
@tarojs/plugin-babel: ^1.2.0 => 1.2.13
@tarojs/plugin-csso: ^1.2.0 => 1.2.13
@tarojs/plugin-sass: ^1.2.0 => 1.2.13
@tarojs/plugin-uglifyjs: ^1.2.0 => 1.2.13
@tarojs/redux: ^1.2.0 => 1.2.13
@tarojs/redux-h5: ^1.2.0 => 1.2.13
@tarojs/router: ^1.2.0 => 1.2.13
@tarojs/taro: ^1.2.0 => 1.2.13
@tarojs/taro-alipay: ^1.2.0 => 1.2.13
@tarojs/taro-h5: ^1.2.0 => 1.2.13
@tarojs/taro-swan: ^1.2.0 => 1.2.13
@tarojs/taro-tt: ^1.2.0 => 1.2.13
@tarojs/taro-weapp: ^1.2.0 => 1.2.13
@tarojs/webpack-runner: ^1.2.0 => 1.2.13
eslint-config-taro: ^1.2.0 => 1.2.13
eslint-plugin-taro: ^1.2.0 => 1.2.13
nervjs: ^1.3.9 => 1.3.12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants