// 权限组件 Authorize.vue
<script>
import check from "../uitl";
export default {
functional: true,
props: {
authority: {
type: Array,
required: true,
},
},
render(h, context) {
const { props, scopedSlots } = context;
return check(props.authority) ? scopedSlots.default() : null;
},
};
</script>
// util/index.js
export const getCurrentAuthority = () => {
return ["admin"];
};
export const check = (authority) => {
const current = getCurrentAuthority();
return current.some((item) => authority.includes(item));
};
全局注册组件
// 使用权限组件
<Authorize :authority="['super']"><el-button>新增</el-button></Authorize>