Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
data-table
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
hookehuyr
2025-02-25 11:49:33 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
83ed065228605881b5bcdb15519f09804789a90f
83ed0652
1 parent
68b0a9c0
✨ feat: 监听formData的变化,当有新的字段添加时重新设置监听器
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
1 deletions
src/views/index.vue
src/views/index.vue
View file @
83ed065
<!--
* @Date: 2022-07-18 10:22:22
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-02-
17 15:02:03
* @LastEditTime: 2025-02-
25 11:48:35
* @FilePath: /data-table/src/views/index.vue
* @Description: 首页
-->
...
...
@@ -237,6 +237,36 @@ const PCommit = ref({});
* 表单结构数据
*/
const formData = ref([]);
// 为每个表单字段创建单独的监听器
// 可以监听到简单组件的字段的值变化,自定义的组件无法监听到
const setupFieldWatchers = () => {
formData.value.forEach((field) => {
watch(
() => field.value,
(newValue, oldValue) => {
if (newValue !== oldValue) {
console.log('字段变化:', {
key: field.key,
name: field.name,
oldValue: oldValue,
newValue: newValue
});
}
}
);
});
};
// TAG: 监听formData的变化,当有新的字段添加时重新设置监听器
watch(
() => formData.value,
() => {
setupFieldWatchers();
},
{ immediate: true }
);
/**
* 格式化表单数据
*/
...
...
Please
register
or
login
to post a comment