basic.md 1.13 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 10 11 12 13 14 15
```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
16
const havePermission = () => {
jim's avatar
jim committed
17 18 19
  return false;
};

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

ReactDOM.render(
jim's avatar
jim committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39
  <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>
    <Authorized authority={Havepermission} noMatch={noMatch}>
      <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>
  </div>
jim's avatar
jim committed
40 41 42
  mountNode,
);
```