vue-vben-admin icon indicating copy to clipboard operation
vue-vben-admin copied to clipboard

表单 RadioButtonGroup重复回调change事件

Open hanxiang-li opened this issue 1 year ago • 3 comments

⚠️ 重要 ⚠️ 在进一步操作之前,请检查下列选项。如果您忽视此模板或者没有提供关键信息,您的 Issue 将直接被关闭

  • [ v ] 已阅读 文档.
  • [ v ] 确保您的代码已是最新或者所报告的 Bug 在最新版本中可以重现. (部分 Bug 可能已经在最近的代码中修复)
  • [ v ] 已在 Issues 中搜索了相关的关键词
  • [ v ] 不是 ant design vue 组件库的 Bug

描述 Bug

在以下表单 schemas 中,会重复触发change事件,一次是antd的事件,一次是 src/hooks/component/useFormItem.ts 中53行的emit事件

{
  field: 'type',
  label: '菜单类型',
  component: 'RadioButtonGroup',
  required: true,
  colProps: { span: 12, },
  componentProps: {
    options: [
      {
        label: '菜单',
        value: 0
      },
      {
        label: '接口',
        value: 1
      },
      {
        label: '按钮',
        value: 2
      },
    ],
    onChange: () => {

    },
  },
},

系统信息

  • 操作系统: mac 14.3.1
  • Node 版本: 16.15.1
  • 包管理器 (npm/yarn/pnpm) 及其版本: 8.14.1

hanxiang-li avatar Feb 21 '24 01:02 hanxiang-li

@hanxiang-li src\components\Form\src\components\RadioButtonGroup.vue

  // Embedded in the form, just use the hook binding to perform form verification
  const [state] = useRuleFormItem(props, 'value', 'change', emitData);

根据注释,貌似和表单验证有关

xachary avatar Feb 21 '24 02:02 xachary

@hanxiang-li antv 源码: image

根据文档 不定义 emits 会透传一个 native 事件 和组件事件(暂没考究此 antv 组件为何这样做) 所以出现两次onChange 此时需要自行区分是否是组件事件,如:

      onChange: (e) => {
        if (e?.nativeEvent?.constructor === Event) {
          // 原生事件
          debugger;
        } else {
          // 组件事件
          debugger;
        }
      },

xachary avatar Feb 21 '24 04:02 xachary

可以取消按钮组的双向绑定 src\components\Form\src\components\RadioButtonGroup.vue image

Zane-Chen avatar Apr 09 '24 01:04 Zane-Chen

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

anncwb avatar Jun 08 '24 01:06 anncwb