# @yangsansuan/vue-auth

> vue 权限控制插件

Latest version **1.0.2** (published 2020-02-19) · ISC license · 0 weekly downloads

## Install

```sh
npm install @yangsansuan/vue-auth
pnpm add @yangsansuan/vue-auth
yarn add @yangsansuan/vue-auth
bun add @yangsansuan/vue-auth
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2020-02-19 |
| First published | 2019-11-12 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 13.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | yangsansuan |
| Maintainers | yangsansuan |
| Keywords | util, kso |

## Links

- npm: https://www.npmjs.com/package/@yangsansuan/vue-auth
- Repository: https://github.com/779102260/vue-auth
- Homepage: https://github.com/779102260/vue-auth#readme
- Issues: https://github.com/779102260/vue-auth/issues
- npm.io page: https://npm.io/package/@yangsansuan/vue-auth

## Dependencies (1)

- [@babel/runtime-corejs2](https://npm.io/package/@babel/runtime-corejs2.md) ^7.6.3

## Alternatives

- [lodash.assign](https://npm.io/package/lodash.assign.md) — 2.3M weekly downloads
- [lodash.chunk](https://npm.io/package/lodash.chunk.md) — 1.8M weekly downloads
- [react-native-ios-utilities](https://npm.io/package/react-native-ios-utilities.md) — 138.5K weekly downloads
- [@technically/lodash](https://npm.io/package/@technically/lodash.md) — 50.9K weekly downloads
- [@fluid-topics/ft-icon](https://npm.io/package/@fluid-topics/ft-icon.md) — 20.6K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2020-02-19
- 1.0.1 — 2019-11-14
- 1.0.0 — 2019-11-12

## README

## 安装

```js
npm install @yangsansuan/vue-auth -S
```

## 使用

1. 引入 & 配置

```js
import Auth from '@yangsansuan/vue-auth'
Vue.use(Auth, options)
```

`options`为插件的配置项：

```js
{
  globalComponets: true, // 默认开启，给全局组件增加权限控制（包括第三方库，比如element，必须先引入库）
  directive: true, // 默认开启，给vue增加`v-auth`指令
  checker: fn // 权限的校验函数，fn必须返回一个Boolean值，false表示隐藏，fn接受一个参数（参见api）
}
```

一般来说只需要配置`checker`即可，此时直接将`options`配置为`checker`函数即可:

```js
const checkAuthFn = function(xx){
  // ...
}
Vue.use(auth, checkAuthFn)
```

2. 使用

- 组件上使用

在组件上添加`auth`属性，其值会注入`checker`函数中，如果函数返回`false`则不会渲染此组件

```html
<my-component auth="xx"></my-component>
```

- 标签上使用

在组件上添加`v-auth`指令，其值会注入`checker`函数中，如果函数返回`false`则会隐藏并删除此标签

```html
<div v-auth="xxx"></div>
```

## apis

### `options`

1. `globalComponets`

Boolean，可选，默认开启。给全局组件增加权限控制，关闭后可能全局组件无法进行权限控制

2. `directive`

Boolean，可选，默认开启。给vue增加`v-auth`指令，在非组件元素上需要使用此指令进行权限控制

3. `checker`

Function，必填。权限的校验函数，用户在此函数中判断是否有权限

此函数接受一个参数（由`auth`属性或`v-auth`指令提供），并要求返回一个`Boolean`值

### `wrap`

```js
wrap(component)
```

用来包裹一个组件，返回一个函数式组件，然后使用返回的组件代替原组件在页面使用，这样就可以使用`auth`属性进行权限控制

### `regDirective`

```js
regDirective()
```

给vue增加`v-auth`指令

## 构建

```
npm run build
```

## npm发版

1. 修改`package.json`中的`version`
2. 发布

```
npm publish
```

---
_Source: https://npm.io/package/@yangsansuan/vue-auth · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
