alibaba / formily

📱🚀 🧩 Cross Device & High Performance Normal Form/Dynamic(JSON Schema) Form/Form Builder -- Support React/React Native/Vue 2/Vue 3
https://formilyjs.org/
MIT License
11.26k stars 1.46k forks source link

[Bug Report] @formily/vue x-decorator-props @click event not work in vue2 #3883

Closed MeetzhDing closed 1 year ago

MeetzhDing commented 1 year ago

Reproduction link

Edit on CodeSandbox

Steps to reproduce

Use @formily/element or other Vue UI library with "x-decorator-props": { onClick: ..., @update: ... }

use vue2 environment please.

What is expected?

event in decorator props will work.

What is actually happening?

In Vue3, events in decorator props work normally

See: https://codesandbox.io/s/formily-vue-decoratorprops-event-work-in-vue3-w42hm5?file=/src/App.vue:0-1914

But in Vue2, events in decorator props not work as expected

See: https://codesandbox.io/s/formily-vue-decoratorprops-event-not-work-in-vue2-wndtty?file=/src/App.vue

Package

@formily/vue@2.2.26


Bug Reason:

In code: https://github.com/alibaba/formily/blob/f51283430e7723510dc82339c43297b83ed59c1f/packages/vue/src/components/ReactiveField.ts#L159-L173

decoratorProps will become { attrs: ... }, it will be infer to props/attrs/events in vue3, but in vue2 attrs cannot become events automatically.

It should deal with like this snippet code https://github.com/alibaba/formily/blob/f51283430e7723510dc82339c43297b83ed59c1f/packages/vue/src/components/ReactiveField.ts#L183-L202