index.vue
554 Bytes
<template>
<slot v-if="hasPermission" />
</template>
<script setup lang="ts">
import { computed } from "vue";
import { useUserStore } from "@/stores";
interface Props {
/** 权限码,支持字符串或字符串数组(满足任一即可) */
authority: string | string[];
}
const props = defineProps<Props>();
const userStore = useUserStore();
const hasPermission = computed(() => {
const authorities = Array.isArray(props.authority) ? props.authority : [ props.authority ];
return userStore.hasAuthority(authorities);
});
</script>