feat:优化FormRender组件的事件处理逻辑,支持动态函数绑定

This commit is contained in:
jxxghp
2025-02-09 11:28:28 +08:00
parent d7038a7d18
commit bdccc71b64

View File

@@ -46,9 +46,9 @@ const parseProps = (rawProps: Record<string, any>, model: Record<string, any>) =
model[value] = newValue
}
} else if (key.startsWith('on')) {
// 处理事件监听
// 处理事件监听,值是函数的代码
const eventName = key.replace('on', '').toLowerCase()
parsedProps[eventName] = (event: any) => model[value](event)
parsedProps[eventName] = new Function('model', `with(model) { return ${value} }`)(model)
} else {
// 如果是表达式,需要绑定
if (typeof value === 'string' && value.startsWith('{{') && value.endsWith('}}')) {