一、wxml 代碼
<button class='tip-text2' style="margin-top:2%;color:#fff" bindtap='scanCode' mode='widthFix'>掃碼</button>
二、js代碼
scanCode: function () {
var that = this;
wx.scanCode({ //掃描API
onlyFromCamera: true,
scanType: ['barCode', 'qrCode'],
success(res) { //掃描成功
var scanCodeMsg = res.path; //擷取二維碼的路徑資訊
console.log(scanCodeMsg) //輸出二維碼資訊
wx.redirectTo({ //調轉到相應頁面
url: '/' + scanCodeMsg,
});
wx.showToast({
title: '成功',
duration: 1000
})
}
})
},
三、官方概述