当前位置:网站首页>Generate QR code in wechat applet
Generate QR code in wechat applet
2022-06-28 04:49:00 【Low code preacher】
Usually in wechat applet , Generating QR code is a very common scenario , But check the official documents , There is no ready-made component to use .
After searching , The generation of two-dimensional code components generally requires the help of a third-party library . The implementation steps are divided into :
- Download third-party libraries
- Install third party libraries
- wxml Generate two-dimensional code in
- js Introduction in
Download third-party libraries
There is a ready-made Library , Can generate QR code . I'm usually used to it gitee download . Enter the download address in the browser
https://gitee.com/WeiDoctor/weapp-qrcode-canvas-2d
The download method is to click the clone button
After downloading, unzip ,dist The files in the directory are what we need
Install third party libraries
The library installation method is also relatively simple , We can now create a new one under the applet directory utils Folder
take dist In the catalog js Copy it all to utils Under the table of contents
This completes the installation of the library
wxml Generate two-dimensional code in
QR code usage canvas Component generation , So you need to be in wxml Add... To the file canvas Components
<canvas type="2d" style="width: 260px; height: 260px;" id="myQrcode"></canvas>
js Third party libraries are introduced into
If you want to use a third-party library, you need to use import Sentence introduction , The specific code is as follows
// pages/test/index.js
import drawQrcode from '../../utils/weapp.qrcode.esm.js'
Page({
/** * Initial data of the page */
data: {
},
/** * Life cycle function -- Monitor page loading */
onLoad(options) {
const query = wx.createSelectorQuery()
query.select('#myQrcode')
.fields({
node: true,
size: true
})
.exec((res) => {
var canvas = res[0].node
// Calling method drawQrcode Generate qr code
drawQrcode({
canvas: canvas,
canvasId: 'myQrcode',
width: 260,
padding: 30,
background: '#ffffff',
foreground: '#000000',
text: ' Personal QR code information ',
})
// Get temporary path ( After you get it , Do whatever you want )
wx.canvasToTempFilePath({
canvasId: 'myQrcode',
canvas: canvas,
x: 0,
y: 0,
width: 260,
height: 260,
destWidth: 260,
destHeight: 260,
success(res) {
console.log(' QR code temporary path :', res.tempFilePath)
},
fail(res) {
console.error(res)
}
})
})
},
/** * Life cycle function -- Listening page first rendering completed */
onReady() {
},
/** * Life cycle function -- Monitor page display */
onShow() {
},
/** * Life cycle function -- Monitor page hidden */
onHide() {
},
/** * Life cycle function -- Monitor page uninstall */
onUnload() {
},
/** * Page related event handler -- Monitor user pull-down action */
onPullDownRefresh() {
},
/** * Handling function of page pull bottom event */
onReachBottom() {
},
/** * Users click the upper right corner to share */
onShareAppMessage() {
}
})
We just need to modify it text The value in the attribute can
summary
This article introduces the method of generating two-dimensional code for small programs , With the help of the third-party library, the development speed can be greatly improved .
边栏推荐
- 一文详解|增长那些事儿
- Analyse complète annuelle du marché chinois de l'audio en 2022
- Ppt production tips
- Pager when importing text files from MySQL
- How to clean the nozzle of Epson l3153 printer
- 如何遍历collections.OrderedDict,服了又忘记items
- Lazy loading and preloading of pictures
- Digital promising, easy to reach, Huawei accelerates the layout of the commercial market with "five pole" star products
- 判断对象中是否存在某一个属性
- Database garbled
猜你喜欢
On the necessity of building a video surveillance convergence platform and its scenario application
Multithreading and high concurrency III: AQS underlying source code analysis and implementation classes
Tiktok actual battle ~ take off the blogger
10:00面试,10:02就出来了 ,问的实在是太...
Matlab exercises -- routine operation of matrix
CI & CD must be known!
The second round of free public classes of the red team is coming ~ 8:00 tomorrow night!
Recommended by Alibaba P8, Fiddler packet capturing tool (I)
测试开发必备技能:安全测试漏洞靶场实战
代码理解:IMPROVING CONVOLUTIONAL MODELS FOR HANDWRITTEN TEXT RECOGNITION
随机推荐
Where does the storm go? Whose pot is the weather forecast wrong?
[proteus simulation] timer 1 external counting interrupt
Multithreading and high concurrency III: AQS underlying source code analysis and implementation classes
Database garbled
27年,微软IE结束了!
快速下载JDK,除了官方Oracle下载,还有国内可以有最新版本的下载地址吗
【Proteus仿真】定时器1外部计数中断
Flexible IP network test tool -- x-launch
The second round of free public classes of the red team is coming ~ 8:00 tomorrow night!
If mysqlcdc sets multiple parallelism, will the incremental data repeat?
How do I get the STW (pause) time of a GC (garbage collector)?
Why is the frame rate calculated by opencv wrong?
Is it better for a novice to open a securities account? Is it safe to open a stock account
Lamaba expression learning and common functional interfaces
在线直播源码,JS动态效果之,侧边栏滚动固定效果
UI自動化測試框架搭建 —— 編寫一個APP自動化
Huawei's 9-year experience as a software testing director
How can we speed up the chunksplitter when CDC extracts MySQL data in full?
Matlab exercises -- routine operation of matrix
RT thread bidirectional linked list (learning notes)