basic.md 1.81 KB
Newer Older
ddcat1115's avatar
ddcat1115 committed
1 2 3 4 5 6 7 8 9
---
order: 0
title: 
  zh-CN: εŸΊη‘€
  en-US: Basic
---

Simplest of usage.

jim's avatar
jim committed
10
```jsx
ddcat1115's avatar
ddcat1115 committed
11 12 13 14
import RenderAuthorized from 'ant-design-pro/lib/Authorized';
import { Alert } from 'antd';

const Authorized = RenderAuthorized('user');
jim's avatar
jim committed
15
const noMatch = <Alert message="No permission." type="error" showIcon />;
ddcat1115's avatar
ddcat1115 committed
16 17

ReactDOM.render(
jim's avatar
jim committed
18
  <Authorized authority="admin" noMatch={noMatch}>
ddcat1115's avatar
ddcat1115 committed
19 20
    <Alert message="Passed!" type="success" showIcon />
  </Authorized>
jim's avatar
jim committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
  mountNode,
);
```

user Array

```jsx
import RenderAuthorized from 'ant-design-pro/lib/Authorized';
import { Alert } from 'antd';

const Authorized = RenderAuthorized('user');
const noMatch = <Alert message="No permission." type="error" showIcon />;

ReactDOM.render(
  <Authorized authority={['user','admin']} noMatch={noMatch}>
    <Alert message="Passed!" type="success" showIcon />
  </Authorized>
  mountNode,
);
```

user Funtion

```jsx
import RenderAuthorized from 'ant-design-pro/lib/Authorized';
import { Alert } from 'antd';

const Authorized = RenderAuthorized('user');
const noMatch = <Alert message="No permission." type="error" showIcon />;

const Havepermission = () => {
  return false;
};

ReactDOM.render(
  <Authorized authority={Havepermission} noMatch={noMatch}>
    <Alert message="Passed!" type="success" showIcon />
  </Authorized>
  mountNode,
);
```


user Promise

```jsx
import RenderAuthorized from 'ant-design-pro/lib/Authorized';
import { Alert } from 'antd';

const Authorized = RenderAuthorized('user');
const noMatch = <Alert message="No permission." type="error" showIcon />;

const Havepermission = new Promise((reslove,reject)=>{
  // Call reslove on behalf of passed
  setTimeout(()=>reslove(),1000)
});

ReactDOM.render(
  <Authorized authority={Havepermission} noMatch={noMatch}>
    <Alert message="Passed!" type="success" showIcon />
  </Authorized>
  mountNode,
);
```