ant-design/components/qrcode/demo/download.tsx
sy296565890 b534c1ecb4
feat: qrcode support render svg (#42570)
* fet: QRCode support type(renderAs)

* fet: QRCode support type(renderAs)

* fet: QRCode support type(renderAs)

* fet: QRCode support type(renderAs)

* fix: Improve type.md,  export QRProps

* Update components/qrcode/demo/type.md

Co-authored-by: lijianan <574980606@qq.com>

* Update components/qrcode/index.tsx

Co-authored-by: lijianan <574980606@qq.com>

* fix: qrCodeProps

* fix: qrcode snap

* Update components/qrcode/demo/type.md

Co-authored-by: lijianan <574980606@qq.com>

* fix: QRCode docs

* fix: QRCode demo

* Update components/qrcode/demo/download.tsx

Co-authored-by: lijianan <574980606@qq.com>

* Update components/qrcode/demo/download.tsx

Co-authored-by: lijianan <574980606@qq.com>

* fix: QRCode snap

* fix: QRCode snap

* fix: 恢复下载示例

---------

Co-authored-by: lijianan <574980606@qq.com>
2023-05-25 13:32:48 +08:00

27 lines
670 B
TypeScript

import { Button, QRCode } from 'antd';
import React from 'react';
const downloadQRCode = () => {
const canvas = document.getElementById('myqrcode')?.querySelector<HTMLCanvasElement>('canvas');
if (canvas) {
const url = canvas.toDataURL();
const a = document.createElement('a');
a.download = 'QRCode.png';
a.href = url;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
};
const App: React.FC = () => (
<div id="myqrcode">
<QRCode value="https://ant.design/" style={{ marginBottom: 16 }} />
<Button type="primary" onClick={downloadQRCode}>
Download
</Button>
</div>
);
export default App;