import React from 'react'; import { Button, QRCode, Segmented, Space } from 'antd'; import type { QRCodeProps } from 'antd'; function doDownload(url: string, fileName: string) { const a = document.createElement('a'); a.download = fileName; a.href = url; document.body.appendChild(a); a.click(); document.body.removeChild(a); } const downloadCanvasQRCode = () => { const canvas = document.getElementById('myqrcode')?.querySelector('canvas'); if (canvas) { const url = canvas.toDataURL(); doDownload(url, 'QRCode.png'); } }; const downloadSvgQRCode = () => { const svg = document.getElementById('myqrcode')?.querySelector('svg'); const svgData = new XMLSerializer().serializeToString(svg!); const blob = new Blob([svgData], { type: 'image/svg+xml;charset=utf-8' }); const url = URL.createObjectURL(blob); doDownload(url, 'QRCode.svg'); }; const App: React.FC = () => { const [renderType, setRenderType] = React.useState('canvas'); return ( setRenderType(val as QRCodeProps['type'])} />
); }; export default App;