How to generate a QR code from a small program: First, create a drawn canvas in the wxml file; then copy [weapp.qrcode.min.js] to the project; finally call [drawQrcode()] to draw QR code.
How to generate QR code by mini program:
1. Create canvas tag
First, create the canvas for drawing in the wxml file, and define width, height, and canvasId. Since the mini program does not have an API for dynamically creating labels, this step cannot be omitted.
<canvas style="width: 200px; height: 200px;" canvas-id="myQrcode"></canvas>
2. Call the drawing method
Since the WeChat applet does not support the introduction of NPM packages, you can copy weapp.qrcode.min.js in the dist directory to the project.
If your applet uses a framework that supports the introduction of NPM packages, such as wepy, you can also install the weapp-qrcode NPM package directly.
npm install weapp-qrcode --save
After introducing the js file, call drawQrcode() to draw the QR code.
import drawQrcode from 'weapp-qrcode' // 或者,将 dist 目录下,weapp.qrcode.min.js 复制到项目目录中 // import drawQrcode from '../../utils/weapp.qrcode.min.js' drawQrcode({ width: 200, height: 200, canvasId: 'myQrcode', text: 'https://github.com/yingye' }
API Description
参数 说明 示例 width 必须,二维码宽度,与canvas的width保持一致 200 height 必须,二维码高度,与canvas的height保持一致 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'
Related learning recommendations: WeChat Mini Program Development Tutorial
The above is the detailed content of How to generate QR code with mini program. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.