Skip to content

Commit 2bea8cd

Browse files
committed
解决自定义指令无法自动注册的问题
1 parent 223badb commit 2bea8cd

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

src/cool/bootstrap/module.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,25 +72,23 @@ export function createModule(app: App) {
7272

7373
if (d) {
7474
Object.assign(e, d);
75-
76-
// 注册组件
77-
e.components?.forEach(async (c: any) => {
78-
const v = await (isFunction(c) ? c() : c);
79-
const n = v.default || v;
80-
app.component(n.name, n);
81-
});
82-
83-
// 注册指令
84-
e.directives?.forEach((v) => {
85-
app.directive(v.name, v.value);
86-
});
87-
88-
// 安装事件
89-
if (d.install) {
90-
d.install(app, d.options);
91-
}
9275
}
9376

77+
// 安装事件
78+
e.install?.(app, d.options);
79+
80+
// 注册组件
81+
e.components?.forEach(async (c: any) => {
82+
const v = await (isFunction(c) ? c() : c);
83+
const n = v.default || v;
84+
app.component(n.name, n);
85+
});
86+
87+
// 注册指令
88+
e.directives?.forEach((v) => {
89+
app.directive(v.name, v.value);
90+
});
91+
9492
// 合并
9593
deepMerge(service, mergeService(e.services || []));
9694

src/modules/demo/directives/color.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default {
2+
created(el: HTMLElement, binding: any) {
3+
el.style.color = binding.value;
4+
}
5+
};

0 commit comments

Comments
 (0)