feat: 自定义指令导入方式优化
This commit is contained in:
parent
f80e9fd8bd
commit
6d3f790a57
@ -1,4 +1,4 @@
|
||||
import { App } from "vue";
|
||||
import { App, Directive } from "vue";
|
||||
import antiShake from "@/directives/modules/global/anti-shake";
|
||||
import throttle from "@/directives/modules/global/throttle";
|
||||
import custom from "@/directives/modules/global/custom";
|
||||
@ -9,14 +9,21 @@ import hasRole from "@/directives/modules/permission/has-role";
|
||||
// install 函数是一个对象中的方法,其作用是将一系列指令对象安装到 Vue 应用实例中,它自带两个参数:app 和 options
|
||||
// app就是vue实例,options则是安装函数的参数(可选)
|
||||
// install 方法的定义就插件对象,install 方法会在引入插件时自动被 vue 调用,并传参 vue 实例和 options
|
||||
|
||||
const list: { [key: string]: Directive } = {
|
||||
antiShake,
|
||||
throttle,
|
||||
custom,
|
||||
hasPerm,
|
||||
hasRole
|
||||
};
|
||||
|
||||
const directives = {
|
||||
install(app: App<Element>) {
|
||||
// 将一系列自定义指令对象安装到 Vue 应用实例中
|
||||
app.directive("antiShake", antiShake);
|
||||
app.directive("throttle", throttle);
|
||||
app.directive("custom", custom);
|
||||
app.directive("hasPerm", hasPerm);
|
||||
app.directive("hasRole", hasRole);
|
||||
for (const key in list) {
|
||||
app.directive(key, list[key]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user