• Stars
    star
    232
  • Rank 172,847 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 6 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Used for vue3 based on ABAC permission verification component

用于Vue3, 基于 ABAC 权限验证

安装

npm i vue-authorized -S
# or
yarn add vue-authorized

使用

一个典型的例子:

authority 参数接收 string/Array/number/boolean , 如果是数组则有任意一个匹配则验证通过

<template>
  <Authorized
    authority="user:add"
  >
    <div>有权限则显示</div>
  </Authorized>
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import Authorized from 'vue-authorized'

export default defineComponent({
  components: {
    Authorized
  },

  setup() {
    // 通常情况从API取得权限集
    fetch('/permissions').then(res => {
      // ['user:add', 'user:del', ...]
      const permissions = res.json()
      // 设置权限, 接收一个数组
      Authorized.setPermissions(permissions)
    })
  }
})
</script>

通过 API Authorized.checked 验证权限

<template>
  <div v-if="hasPerm">有权限则显示</div>
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import Authorized from 'vue-authorized'

export default defineComponent({
  components: {
    Authorized
  },

  setup() {
    // 接收第二个参数 target,默认为true, 权限通过则返回 target
    // Authorized.checked('user:add', 'hello') // => 'hello'

    const hasPerm = Authorized.checked('user:add')

    return {
      hasPerm,
    }
  }
})
</script>

接收插槽 no-match 没有权限的情况下显示内容:

<template>
  <Authorized
    authority="user:add"
  >
    <div>有权限则显示</div>

    <template v-slot:no-match>
      无权限
    </template>
  </Authorized>
</template>

无权限传入 null 或 空数组

<script lang="ts">
import Authorized from 'vue-authorized'

Authorized.setPermissions(null)
// or
Authorized.setPermissions([])

属性

参数 描述 类型 默认值 是否必填
authority 校验是否有权限 string/boolean/number/unknow[] -

事件

参数 描述
no-match 权限校验不通过触发

LICENSE

MIT

More Repositories

1

nav

🔍 发现导航 , 最强轻量级导航网站
TypeScript
2,114
star
2

git-manual

:octocat: git command reference manual; Git常用命令参考手册,涵盖了在开发中用到的git命令
919
star
3

awesome-web-editor

🔨 Open source WEB editor summary
Python
769
star
4

tomato-work

🍅 个人事务管理系统
TypeScript
596
star
5

boomb

💣 Manage your pictures easily for Github/Gitee. 基于 Github/Gitee 轻松管理您的存储图库
Vue
323
star
6

linux-manual

🐧 Linux command reference manual; Linux 常用命令参考手册, 日常运维的最佳拍档。
312
star
7

gosh

🛺 Golang utility library, With additional functions such as JavaScript/Python! Golang实用程序库。
Go
176
star
8

tomato-work-server

🍅 Tomato Work Server for Egg.js
JavaScript
52
star
9

egg-mailer

🥚 mailer plugin for egg
JavaScript
22
star
10

egg-crypto

🥚 crypto plugin for egg
JavaScript
12
star
11

weapp-input-frame

input-frame for weapp
JavaScript
11
star
12

micro-design-editor

Micro page editing component for react
JavaScript
9
star
13

ip

🐺 Public IP for Go
Go
8
star
14

tomato-work-mini

🍅 个人事物管理系统
JavaScript
8
star
15

wifi

📶 Quickly fetch your WiFi password and if needed, generate a QR code of your WiFi to allow phones to easily connect.
Go
7
star
16

github-oauth2

Github OAuth2 for Go
Go
6
star
17

xjh22222228

4
star
18

translate-tw

将文件内的中文简体转换成繁体。
Go
3
star
19

xss-ctf

XSS-CTF 一个练习和入门的XSS平台
JavaScript
3
star
20

python-check-updates

⚡️ Find the latest version of your requirements.txt current dependency package.
Go
3
star
21

v-drag-move

🤚 v-drag-move
Vue
3
star
22

vscode-translate-tw

VSCode 将文件内的中文简体转换成繁体
TypeScript
3
star
23

js-ant

js-ant
JavaScript
2
star
24

iterm2-zmodem

iTerm2 zmodem shell
Shell
2
star
25

vue-app

📱基于vue构建的移动端网站
Vue
2
star
26

nav-web

TypeScript
2
star
27

mac

get mac address for go.
Go
1
star
28

public

1
star
29

clear

Clear terminal screen
Go
1
star
30

issue-helper

Vue
1
star
31

battery

TypeScript
1
star