Skip to content

Commit 48cc3cd

Browse files
committed
添加权限自定义指令
1 parent cbeb045 commit 48cc3cd

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/directive/index.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* @Description:
3+
* @Author: gumingchen
4+
5+
* @Date: 2021-04-27 09:26:25
6+
* @LastEditors: gumingchen
7+
* @LastEditTime: 2021-04-27 09:34:06
8+
*/
9+
import { $isAuth } from '@/utils'
10+
import { IApp } from '@/utils/index.type'
11+
12+
export default {
13+
install: function (app: IApp): void {
14+
app.directive('permission', (el, binding): void => {
15+
const permission = binding.value
16+
const result = $isAuth(permission)
17+
if (!result) {
18+
el.remove()
19+
}
20+
})
21+
}
22+
}

src/main.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
* @Date: 2021-04-06 13:58:51
66
* @LastEditors: gumingchen
7-
* @LastEditTime: 2021-04-16 16:22:04
7+
* @LastEditTime: 2021-04-27 09:34:50
88
*/
99
import { createApp } from 'vue'
1010
import App from '@/App.vue'
@@ -13,6 +13,7 @@ import store from '@/store'
1313
import Element from '@/element'
1414
import I18n from '@/i18n'
1515
import Components from '@/components/index'
16+
import Directive from '@/directive'
1617
import '@/assets/icon' // svg 图标引入
1718
import '@/assets/sass/index.scss'
1819

@@ -23,4 +24,5 @@ app.use(store)
2324
.use(Element)
2425
.use(I18n)
2526
.use(Components)
27+
.use(Directive)
2628
.mount('#app')

src/utils/index.type.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
* @Date: 2021-01-25 16:39:22
88
* @LastEditors: gumingchen
9-
* @LastEditTime: 2021-02-04 10:13:57
9+
* @LastEditTime: 2021-04-27 09:31:11
1010
*/
1111
export interface IObject {
1212
[key: string]: any
@@ -27,6 +27,7 @@ export interface IApp {
2727
}
2828
}
2929
}
30+
directive: (arg0: string, arg1: (el: any, binding: any) => void) => void
3031
}
3132

3233
export enum ContentType {

0 commit comments

Comments
 (0)