yanjinhui
10 天以前 c5de0d98241f8c8349fa38851b77efcfc61e4d26
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<script setup lang="tsx">
import { ContentWrap } from '@/components/ContentWrap'
import { ref, unref } from 'vue'
import { ElDivider, ElRow, ElCol } from 'element-plus'
import { hasPermi } from '@/components/Permission'
 
const permission = ref('add')
 
setTimeout(() => {
  permission.value = 'view'
}, 3000)
</script>
 
<template>
  <ContentWrap>
    <ElDivider>组件方式判断(已经全局注册,支持动态修改)</ElDivider>
    <ElRow :gutter="20">
      <ElCol :span="8">
        新增权限:
        <Permission permission="add">
          <BaseButton type="primary"> Add </BaseButton>
        </Permission>
      </ElCol>
      <ElCol :span="8">
        删除权限:
        <Permission permission="delete">
          <BaseButton type="danger"> Delete </BaseButton>
        </Permission>
      </ElCol>
      <ElCol :span="8">
        3秒后切换查看权限:
        <Permission :permission="permission">
          <BaseButton type="primary"> View </BaseButton>
        </Permission>
      </ElCol>
    </ElRow>
 
    <ElDivider>指令方式判断(已经全局注册,不支持动态修改)</ElDivider>
    <ElRow :gutter="20">
      <ElCol :span="8">
        新增权限:
        <BaseButton v-hasPermi="'add'" type="primary"> Add </BaseButton>
      </ElCol>
      <ElCol :span="8">
        删除权限:
        <BaseButton v-hasPermi="'delete'" type="danger"> Delete </BaseButton>
      </ElCol>
      <ElCol :span="8">
        3秒后切换查看权限(无法动态修改):
        <BaseButton v-hasPermi="permission" type="primary"> View </BaseButton>
      </ElCol>
    </ElRow>
 
    <ElDivider>函数方式判断</ElDivider>
    <ElRow :gutter="20">
      <ElCol :span="8">
        新增权限:
        <BaseButton v-if="hasPermi('add')" type="primary"> Add </BaseButton>
      </ElCol>
      <ElCol :span="8">
        删除权限:
        <BaseButton v-if="hasPermi('delete')" type="danger"> Delete </BaseButton>
      </ElCol>
      <ElCol :span="8">
        3秒后切换查看权限:
        <BaseButton v-if="hasPermi(unref(permission))" type="primary"> View </BaseButton>
      </ElCol>
    </ElRow>
  </ContentWrap>
</template>