二维码生成
- react-qr-code:
react-qr-code专注于二维码的生成,允许开发者通过简单的API生成高质量的二维码图像。它支持多种自定义选项,如颜色、大小和边距,使得生成的二维码可以完美融入应用的设计中。
- react-qr-reader:
react-qr-reader不提供二维码生成的功能,主要用于读取和解析二维码。
二维码生成与读取库是用于在Web应用程序中实现二维码功能的工具。它们允许开发者轻松地生成二维码图像或读取用户通过摄像头扫描的二维码。这些库在移动应用和网页应用中都非常有用,尤其是在需要快速信息传递和数据输入的场景中。使用这些库可以大大简化二维码的集成过程,提高用户体验和交互效率。
react-qr-code专注于二维码的生成,允许开发者通过简单的API生成高质量的二维码图像。它支持多种自定义选项,如颜色、大小和边距,使得生成的二维码可以完美融入应用的设计中。
react-qr-reader不提供二维码生成的功能,主要用于读取和解析二维码。
选择react-qr-code如果您需要一个简单、轻量级的解决方案来生成二维码。它提供了灵活的API和多种自定义选项,适合需要快速生成二维码的项目。
选择react-qr-reader如果您需要一个功能全面的解决方案来读取二维码。它支持实时扫描和多种摄像头配置,适合需要复杂二维码读取功能的应用。
A
npm i react-qr-code
When using this library with React Native, you will also need to have react-native-svg installed.
npm i react-native-svg
cd ios && pod install
import React from "react";
import ReactDOM from "react-dom";
import QRCode from "react-qr-code";
ReactDOM.render(<QRCode value="hey" />, document.getElementById("Container"));
Note: If the QR code is likely to appear next to dark objects, you will need to wrap it in a light-colored container to preserve the 'quiet zone', e.g.
<div style={{ background: 'white', padding: '16px' }}>
<QRCode ... />
</div>
Responsive QR code example:
// Can be anything instead of `maxWidth` that limits the width.
<div style={{ height: "auto", margin: "0 auto", maxWidth: 64, width: "100%" }}>
<QRCode
size={256}
style={{ height: "auto", maxWidth: "100%", width: "100%" }}
value={value}
viewBox={`0 0 256 256`}
/>
</div>
| prop | type | default value | platform |
|---|---|---|---|
bgColor | string | '#FFFFFF' | web, ios, android |
fgColor | string | '#000000' | web, ios, android |
level | string ('L' 'M' 'Q' 'H') | 'L' | web, ios, android |
size | number | 256 | web, ios, android |
title | string | web | |
value | string | web, ios, android |
Adheres to the official QR spec and can store up to 2953 characters in value.
MIT