微信小程序實現二維碼生成器
更新時間:2023年01月09日 16:49:27 作者:失散多年的哥哥
這篇文章主要為大家詳細介紹了如何通過微信小程序開發(fā)一個簡單的二維碼生成器,文中的示例代碼講解詳細,感興趣的小伙伴可以和小編一起學習一下
一、項目展示
項目是一個簡單實用的二維碼生成器。
使用者可以在生成器中輸入文字生成二維碼,也可以在識別器中識別二維碼的內容

二、項目核心代碼
二維碼生成
// pages/home/home.js
Page({
data:{
qrMsg: '',
recognizeMsg: '',
isShowMsg: false,
isShowResult: false,
showClear: true,
},
onLoad:function(options){
// 頁面初始化 options為頁面跳轉所帶來的參數
this.setData({
isShowMsg: false,
isShowResult: true,
})
},
onReady:function(){
// 頁面渲染完成
},
onShow:function(){
// 頁面顯示
},
onHide:function(){
// 頁面隱藏
},
onUnload:function(){
// 頁面關閉
},
// 生成二維碼
makeQrcode: function(e) {
this.setData({
isShowMsg: false,
isShowResult: true,
})
console.log(this.data.qrMsg + "家")
if (this.data.qrMsg == "") {
wx.showToast({
title: '二維碼內容不能為空',
icon: 'loading',
duration: 500
})
return
}
var that = this
wx.navigateTo({
url: '../main/main?msg=' + that.data.qrMsg,
success: function(res){
// success
},
fail: function() {
// fail
},
complete: function() {
// complete
}
})
},
bindInput: function(e) {
console.log(e.detail.value)
this.setData({
qrMsg: e.detail.value
})
if (this.data['qrMsg'].length > 1) {
this.setData({
showClear: false
})
} else {
this.setData({
showClear: true
})
}
},
// 清空
bindClearAll: function(res) {
wx.redirectTo({
url: '../home/home',
})
},
// 識別二維碼
recognizeCode: function() {
this.setData({
isShowMsg: true,
isShowResult: false,
recognizeMsg: "",
})
var that = this
wx.scanCode({
success: function(res){
// success
console.log(res)
that.setData({
recognizeMsg: res["result"]
})
},
fail: function() {
// fail
},
complete: function() {
// complete
}
})
},
})
<!--pages/home/home.wxml-->
<view class="container-box">
<!--生成器-->
<view class="home-section">
<view class="home-section-title" bindtap="makeQrcode">
<text class="home-section-title-make">生成器</text>
<image class="home-next-btn" src="../../images/next.png"></image>
</view>
<view hidden="{{isShowMsg}}">
<textarea maxlength="-1" bindinput="bindInput" class="recognize-content" placeholder="請輸入二維碼的文本內容"/>
<view class="home-clear"><text hidden="{{showClear}}" bindtap="bindClearAll">CLEAR</text></view>
</view>
</view>
<!--識別器-->
<view class="home-section">
<view class="home-section-title" bindtap="recognizeCode">
<text class="home-section-title-recognize">識別器</text>
<image class="home-next-btn" src="../../images/next.png"></image>
</view>
<view hidden="{{isShowResult}}" class="recog-text">
<textarea maxlength="-1" value="{{recognizeMsg}}" class="recognize-content"/>
</view>
</view>
</view>到此這篇關于微信小程序實現二維碼生成器的文章就介紹到這了,更多相關小程序二維碼生成器內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
CascadeView級聯組件實現思路詳解(分離思想和單鏈表)
本文介紹自己最近做省市級聯的類似的級聯功能的實現思路,為了盡可能地做到職責分離跟表現與行為分離,這個功能拆分成了2個組件并用到了單鏈表來實現關鍵的級聯邏輯,下一段有演示效果的gif圖2016-04-04
Java中int與integer的區(qū)別(基本數據類型與引用數據類型)
這篇文章主要介紹了int與integer的區(qū)別(基本數據類型與引用數據類型),簡單的說 int 是基本數據類型,integer 是引用數據類型,具體區(qū)別詳解大家參考下本文2017-02-02

