Giter VIP home page Giter VIP logo

weapp-qrcode's Introduction

weapp-qrcode

weapp.qrcode.js 在 微信小程序 中,快速生成二维码

Usage

先在 wxml 文件中,创建绘制的 canvas,并定义好 width, height, canvasId

<canvas style="width: 200px; height: 200px;" canvas-id="myQrcode"></canvas>

直接引入 js 文件,使用 drawQrcode() 绘制二维码。!!!在 调用 drawQrcode() 方法之前,一定要确保可以获取到 canvas context

在 v0.6.0 版本构建出多个文件,详情移步Build Files说明

// 将 dist 目录下,weapp.qrcode.esm.js 复制到项目目录中
import drawQrcode from '../../utils/weapp.qrcode.esm.js'

drawQrcode({
  width: 200,
  height: 200,
  canvasId: 'myQrcode',
  text: 'https://github.com/yingye'
})

如果项目使用了 wepy 框架,可直接安装 weapp-qrcode npm包。

npm install weapp-qrcode --save
import drawQrcode from 'weapp-qrcode'

drawQrcode({
  width: 200,
  height: 200,
  canvasId: 'myQrcode',
  text: 'https://github.com/yingye'
})

DEMO

demo-img

API

drawQrcode([options])

options

Type: Object

参数 说明 示例
width 必须,二维码宽度,与canvaswidth保持一致 200
height 必须,二维码高度,与canvasheight保持一致 200
canvasId 必须,绘制的canvasId 'myQrcode'
text 必须,二维码内容 'https://github.com/yingye'
typeNumber 非必须,二维码的计算模式,默认值-1 8
correctLevel 非必须,二维码纠错级别,默认值为高级,取值:{ L: 1, M: 0, Q: 3, H: 2 } 1
background 非必须,二维码背景颜色,默认值白色 '#ffffff'
foreground 非必须,二维码前景色,默认值黑色 '#000000'

TIPS

weapp.qrcode.js 二维码生成部分借鉴了 jquery-qrcode 源码,可以参考 jquery-qrcode

weapp-qrcode's People

Contributors

yingye avatar

Watchers

James Cloos avatar Terrance Wang 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.