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

jim's avatar
jim committed
8 9
Authorized demo used

jim's avatar
jim committed
10 11 12 13 14 15 16 17
```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 />;


jim's avatar
jim committed
18
const havePermission = () => {
jim's avatar
jim committed
19 20 21
  return false;
};

jim's avatar
jim committed
22
const havePermissionAsync = new Promise((resolve,reject)=>{
jim's avatar
jim committed
23 24
  // Call resolve on behalf of passed
  setTimeout( ()=> resolve() , 1000)
jim's avatar
jim committed
25 26 27
});

ReactDOM.render(
jim's avatar
jim committed
28 29 30 31 32 33 34
  <div>
    <Authorized authority="admin" noMatch={noMatch}>
      <Alert message="user Passed!" type="success" showIcon />
    </Authorized>
    <Authorized authority={['user','admin']} noMatch={noMatch}>
      <Alert message="Use Array as a parameter passed!" type="success" showIcon />
    </Authorized>
jim's avatar
jim committed
35
    <Authorized authority={havePermission} noMatch={noMatch}>
jim's avatar
jim committed
36 37 38 39 40
      <Alert message="Use function as a parameter passed!" type="success" showIcon />
    </Authorized>
    <Authorized authority={havePermissionAsync} noMatch={noMatch}>
      <Alert message="Use Promise as a parameter passed!" type="success" showIcon />
    </Authorized>
41 42
  </div>,
  mountNode
jim's avatar
jim committed
43 44
);
```