mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-16 09:39:10 +08:00
27 lines
670 B
TypeScript
27 lines
670 B
TypeScript
|
import React from 'react';
|
||
|
import { QRCode, Button } from 'antd';
|
||
|
|
||
|
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;
|