staff/components/examples/permission-button.vue

29 lines
608 B
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view v-if="showButton">
<slot></slot>
</view>
</template>
<script setup>
import { computed, inject } from 'vue'
import { hasPermission } from '@/utils/permission'
const props = defineProps({
// 功能类型与permission.js中的permissionMap对应
type: {
type: String,
required: true
}
})
// 尝试从父级组件注入权限数组,如果没有则使用空数组
const userPermissions = inject('userPermissions', [])
// 计算是否显示按钮
const showButton = computed(() => {
return hasPermission(props.type, userPermissions)
})
</script>
<style>
</style>