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

无法用代码触发组件(Button)的 Tap 事件 #15614

Open
loocor opened this issue May 3, 2024 · 0 comments
Open

无法用代码触发组件(Button)的 Tap 事件 #15614

loocor opened this issue May 3, 2024 · 0 comments
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@loocor
Copy link

loocor commented May 3, 2024

相关平台

微信小程序

复现仓库

https://gist.github.com/loocor/2945eb43532b4e878a054cc491ac97aa
小程序基础库: 3.4.2
使用框架: React

复现步骤

  1. 创建了包含部分表单字段、contact 类型按钮的页面(如上 gist 代码所示);
  2. 关键的两个按钮组件:一个是“用于检查数据的按钮”,另一个是 “在线咨询” 按钮;
  3. 用于检查数据的按钮被点击后,通过 jQuery-like API 语法取得 “在线咨询” 按钮并触发其 “Tap” 事件;
  4. 编译到 Wechat Devtools 工具中点击 “用于检查数据的按钮” 即报错;

期望结果

点击 “用于检查数据的按钮” 后,能够按其 onClick 事件代码那样,触发 “在线咨询” 按钮被点击

实际结果

Wechat Devtools 工具控制台输出错误信息:

TypeError: event.initEvent is not a function
    at Function.$.Event (._node_modules_.pnpm_@tarojs [email protected]_node_modules_@tarojs_extend_src_jquery_event.js:278)
    at Z.$.fn.trigger (._node_modules_.pnpm_@tarojs [email protected]_node_modules_@tarojs_extend_src_jquery_event.js:236)
    at onClick (index.jsx?5256:232)
    at handleClick (._node_modules_.pnpm_@nutui [email protected][email protected][email protected][email protected]_node_modules_@nutui_nutui-react-taro_dist_esm_button.taro-CjH840d8.js:30)
    at TaroElement.onClick (._node_modules_.pnpm_@nutui [email protected][email protected][email protected][email protected]_node_modules_@nutui_nutui-react-taro_dist_esm_button.taro-CjH840d8.js:48)
    at TaroElement.handler (.._src_dom_event-target.ts:47)
    at TaroElement.dispatchEvent (.._src_dom_element.ts:329)
    at .._src_render.ts:119
    at Object.exports.runWithPriority ([email protected][email protected]_node_modules_react-reconciler_cjs_react-reconciler.production.min.js:226)
    at TaroHooks.<anonymous> (.._src_render.ts:118)(env: macOS,mp,1.06.2402040; lib: 3.4.0)

环境信息

👽 Taro v3.6.28

(node:56740) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)

  Taro CLI 3.6.28 environment info:
    System:
      OS: macOS 14.4.1
      Shell: 5.9 - /bin/zsh
    Binaries:
      Node: 22.0.0 - /usr/local/bin/node
      npm: 10.5.1 - /usr/local/bin/npm
    npmPackages:
      @tarojs/cli: 3.6.28 => 3.6.28 
      @tarojs/components: 3.6.28 => 3.6.28 
      @tarojs/extend: ^3.6.28 => 3.6.28 
      @tarojs/helper: 3.6.28 => 3.6.28 
      @tarojs/plugin-framework-react: 3.6.28 => 3.6.28 
      @tarojs/plugin-html: 3.6.28 => 3.6.28 
      @tarojs/plugin-platform-alipay: 3.6.28 => 3.6.28 
      @tarojs/plugin-platform-h5: 3.6.28 => 3.6.28 
      @tarojs/plugin-platform-jd: 3.6.28 => 3.6.28 
      @tarojs/plugin-platform-qq: 3.6.28 => 3.6.28 
      @tarojs/plugin-platform-swan: 3.6.28 => 3.6.28 
      @tarojs/plugin-platform-tt: 3.6.28 => 3.6.28 
      @tarojs/plugin-platform-weapp: 3.6.28 => 3.6.28 
      @tarojs/react: 3.6.28 => 3.6.28 
      @tarojs/runtime: 3.6.28 => 3.6.28 
      @tarojs/shared: 3.6.28 => 3.6.28 
      @tarojs/taro: 3.6.28 => 3.6.28 
      @tarojs/taro-loader: 3.6.28 => 3.6.28 
      @tarojs/webpack5-runner: 3.6.28 => 3.6.28 
      babel-preset-taro: 3.6.28 => 3.6.28 
      eslint-config-taro: 3.6.28 => 3.6.28 
      react: ^18.0.0 => 18.2.0 


补充信息

使用 ref 模式如 refContact.current?.click() 还是出错,提示 click() 不是函数

@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels May 3, 2024
This was referenced May 4, 2024
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
Status: Todo
Development

No branches or pull requests

1 participant