search
HomeWeChat AppletMini Program DevelopmentHow to generate QR code with mini program

How to generate QR code with mini program

Aug 14, 2020 pm 02:30 PM
QR codeApplets

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 with mini program

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 &#39;weapp-qrcode&#39;
// 或者,将 dist 目录下,weapp.qrcode.min.js 复制到项目目录中
// import drawQrcode from &#39;../../utils/weapp.qrcode.min.js&#39;
drawQrcode({
  width: 200,
  height: 200,
  canvasId: &#39;myQrcode&#39;,
  text: &#39;https://github.com/yingye&#39;
}

API Description

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

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!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

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

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.