{"id":13446110,"url":"https://github.com/yingye/weapp-qrcode","last_synced_at":"2025-05-14T18:07:12.767Z","repository":{"id":40636924,"uuid":"119684433","full_name":"yingye/weapp-qrcode","owner":"yingye","description":"weapp.qrcode.js 在 微信小程序 中，快速生成二维码","archived":false,"fork":false,"pushed_at":"2023-01-04T12:20:43.000Z","size":1310,"stargazers_count":1676,"open_issues_count":33,"forks_count":979,"subscribers_count":21,"default_branch":"master","last_synced_at":"2025-05-14T18:07:06.680Z","etag":null,"topics":["qrcode","weapp","wechat","wechat-mini-program","wepy"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yingye.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-31T12:29:37.000Z","updated_at":"2025-05-14T16:23:45.000Z","dependencies_parsed_at":"2023-02-02T12:02:07.757Z","dependency_job_id":null,"html_url":"https://github.com/yingye/weapp-qrcode","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yingye%2Fweapp-qrcode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yingye%2Fweapp-qrcode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yingye%2Fweapp-qrcode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yingye%2Fweapp-qrcode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yingye","download_url":"https://codeload.github.com/yingye/weapp-qrcode/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254198515,"owners_count":22030966,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["qrcode","weapp","wechat","wechat-mini-program","wepy"],"created_at":"2024-07-31T05:00:45.900Z","updated_at":"2025-05-14T18:07:07.758Z","avatar_url":"https://github.com/yingye.png","language":"JavaScript","funding_links":[],"categories":["Libraries","JavaScript","微信小程序WePY框架开发资源汇总 ![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)"],"sub_categories":["QR code","WePY开源组件"],"readme":"# weapp-qrcode\n\n[![npm version](https://badge.fury.io/js/weapp-qrcode.svg)](https://badge.fury.io/js/weapp-qrcode)\n[![change-log](https://img.shields.io/badge/changelog-md-blue.svg)](https://github.com/yingye/weapp-qrcode/blob/master/CHANGELOG.md)\n\nweapp.qrcode.js 在 微信小程序 中，快速生成二维码\n\n## Usage\n\n先在 wxml 文件中，创建绘制的 `canvas`，并定义好 `width`, `height`, `canvasId` 。\n\n```html\n\u003ccanvas style=\"width: 200px; height: 200px;\" canvas-id=\"myQrcode\"\u003e\u003c/canvas\u003e\n```\n\n直接引入 js 文件，使用 `drawQrcode()` 绘制二维码。!!!在 调用 `drawQrcode()` 方法之前，一定要确保可以获取到 `canvas context` 。\n\n在 v0.6.0 版本构建出多个文件，详情移步[Build Files说明](https://github.com/yingye/weapp-qrcode/blob/master/dist/README.md)。\n\n```js\n// 将 dist 目录下，weapp.qrcode.esm.js 复制到项目目录中\nimport drawQrcode from '../../utils/weapp.qrcode.esm.js'\n\ndrawQrcode({\n  width: 200,\n  height: 200,\n  canvasId: 'myQrcode',\n  // ctx: wx.createCanvasContext('myQrcode'),\n  text: 'https://github.com/yingye',\n  // v1.0.0+版本支持在二维码上绘制图片\n  image: {\n    imageResource: '../../images/icon.png',\n    dx: 70,\n    dy: 70,\n    dWidth: 60,\n    dHeight: 60\n  }\n})\n```\n\n如果项目使用了 wepy 框架，可直接安装 `weapp-qrcode` npm包。\n\n```\nnpm install weapp-qrcode --save\n```\n\n```js\nimport drawQrcode from 'weapp-qrcode'\n\ndrawQrcode({\n  width: 200,\n  height: 200,\n  canvasId: 'myQrcode',\n  text: 'https://github.com/yingye'\n})\n```\n\n## DEMO\n\n\u003cimg src=\"./examples/demo.jpg\" width=300 \u003e\n\n更多 demo 可以参考 [examples目录](https://github.com/yingye/weapp-qrcode/tree/master/examples)，示例包含原生语法及WePY、mpvue、Taro框架。\n\n## API\n\n### drawQrcode([options])\n\n#### options\n\nType: Object\n\n| 参数 | 说明 | 示例|\n| ------ | ------ | ------ |\n| width | 必须，二维码宽度，与`canvas`的`width`保持一致 | 200 |\n| height | 必须，二维码高度，与`canvas`的`height`保持一致 | 200 |\n| canvasId | 非必须，绘制的`canvasId` | `'myQrcode'` |\n| ctx | 非必须，绘图上下文，可通过 `wx.createCanvasContext('canvasId')` 获取，v1.0.0+版本支持 | `'wx.createCanvasContext('canvasId')'` |\n| text | 必须，二维码内容 | 'https://github.com/yingye' |\n| typeNumber | 非必须，二维码的计算模式，默认值-1 | 8 |\n| correctLevel | 非必须，二维码纠错级别，默认值为高级，取值：`{ L: 1, M: 0, Q: 3, H: 2 }` | 1 |\n| background | 非必须，二维码背景颜色，默认值白色 | `'#ffffff'` |\n| foreground | 非必须，二维码前景色，默认值黑色 | `'#000000'` |\n| _this | 非必须，若在组件中使用，需要传入，v0.7.0+版本支持 | this |\n| callback | 非必须，绘制完成后的回调函数，v0.8.0+版本支持。安卓手机兼容性问题，可通过自行设置计时器来解决，更多可以参考 [issue #18](https://github.com/yingye/weapp-qrcode/issues/18) | `function (e) { console.log('e', e) }` |\n| x | 非必须，二维码绘制的 x 轴起始位置，默认值0，v1.0.0+版本支持 | 100 |\n| y | 非必须，二维码绘制的 y 轴起始位置，默认值0，v1.0.0+版本支持 | 100 |\n| image | 非必须，在 canvas 上绘制图片，**层级高于二维码**，v1.0.0+版本支持，更多可参考[drawImage](https://developers.weixin.qq.com/miniprogram/dev/api/CanvasContext.drawImage.html) | `{ imageResource: '', dx: 0, dy: 0, dWidth: 100, dHeight: 100 }` |\n\n\n**位置信息可以参见下图：**\n\n\u003cimage src=\"./examples/api.png\" width=500 height=500\u003e\n\n## TIPS\n\nweapp.qrcode.js 二维码生成部分借鉴了 jquery-qrcode 源码，可以参考 [jquery-qrcode](https://github.com/jeromeetienne/jquery-qrcode)。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyingye%2Fweapp-qrcode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyingye%2Fweapp-qrcode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyingye%2Fweapp-qrcode/lists"}