Skip to content

Commit 8bda4ec

Browse files
committed
fix(fe): update behavior merging logic to prioritize component properties and data
1 parent 20a3e6b commit 8bda4ec

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

fe/packages/service/src/core/utils.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -349,19 +349,19 @@ export function mergeBehaviors(obj, behaviors) {
349349
behavior.behaviors.forEach(b => merge(target, b))
350350
}
351351

352-
// 合并 properties
353-
// 规则: 靠后的 behavior 覆盖靠前的, 引用者覆盖被引用者
354-
if (behavior.properties) {
355-
target.properties = { ...target.properties, ...behavior.properties }
356-
}
352+
// 合并 properties
353+
// 规则: 组件本身覆盖 behavior, 靠后的 behavior 覆盖靠前的, 引用者覆盖被引用者
354+
if (behavior.properties) {
355+
target.properties = { ...behavior.properties, ...target.properties }
356+
}
357357

358358
// 合并 data
359-
// 规则: 对象类型深度合并, 其他类型按优先级覆盖
359+
// 规则: 组件本身覆盖 behavior, 对象类型深度合并, 其他类型按优先级覆盖
360360
if (behavior.data) {
361361
if (!target.data) {
362362
target.data = {}
363363
}
364-
target.data = deepMergeData(target.data, behavior.data)
364+
target.data = deepMergeData(behavior.data, target.data)
365365
}
366366

367367
// 合并生命周期函数
@@ -389,11 +389,11 @@ export function mergeBehaviors(obj, behaviors) {
389389
}
390390
}
391391

392-
// 合并 methods
393-
// 规则: 靠后的 behavior 覆盖靠前的, 引用者覆盖被引用者
394-
if (behavior.methods) {
395-
target.methods = { ...target.methods, ...behavior.methods }
396-
}
392+
// 合并 methods
393+
// 规则: 组件本身覆盖 behavior, 靠后的 behavior 覆盖靠前的, 引用者覆盖被引用者
394+
if (behavior.methods) {
395+
target.methods = { ...behavior.methods, ...target.methods }
396+
}
397397

398398
// 合并 relations
399399
// 规则: 靠后的覆盖靠前的

0 commit comments

Comments
 (0)