GithubHelp home page GithubHelp logo

qrcode's Introduction

@nicolaz/qrcode

跨浏览器的 JavaScript 版 QRCode 生成库。Fork 自 QRcode,使其支持 ESM 环境。

安装

npm i @nicolaz/qrcode

使用

import QRCode from '@nicolaz/qrcode';

原生 JavaScript 中

new QRCode(document.getElementById('qrcode'), 'http://www.baidu.com');

React

function QRCode({ url }) {
  const el = useRef(null);
  useEffect(() => {
    new QRCode(el.current, url);
  }, []);

  return (
    <div ref={el} className="qrcode" />
  );
}

API

构造函数参数

Element

Type: HTMLElement | String

如果是 String 则认为是元素的 ID 选择器

Options

Type: Object | String

如果是 Object 则认为是一个配置对象:

属性 描述 默认值
text QRCode 数据源
width 渲染宽度 256
height 渲染高度 256
colorDark 前景色 "#000000"
colorLight 背景色 "#ffffff"
correctLevel 容错级别 QRCode.correctLevel.H
QRCode.correctLevel
  • QRCode.correctLevel.L
  • QRCode.correctLevel.M
  • QRCode.correctLevel.Q
  • QRCode.correctLevel.H

实例方法

qrcode.clear()

清除 QR code

qrcode.makeCode(text)

重新渲染另一个 QR code

License

MIT © nicolaszhao

qrcode's People

Contributors

nicolaszhao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.