調取手機攝像頭
<view @click="scan">掃碼驗證</view>
scan() { //掃碼驗證
var _this = this; uni.scanCode({
onlyFromCamera: true, //為true只允許相機掃碼,不加允許相冊掃碼 success: function(res) { uni.showToast({ title: '掃碼成功' }) }, fail: function(err) { console.log('掃碼失敗', err) } }) },
掃碼成功的參數在res.result里面
生成二維碼圖片
下載weapp-qrcode.js文件
鏈接:https://pan.baidu.com/s/1TkSregltj_b5kc9xjhNY-g 提取碼:gurm
<view class="qrcode">
<canvas style="width: 200upx;height: 200upx;" canvas-id="couponQrcode"></canvas>
</view>
<script> const qrCode = require('../../libs/weapp-qrcode.js') methods: { //二維碼生成工具
couponQrCode() { new qrCode('couponQrcode', { text: "加入你所需要的參數", width: 100, height: 100, showLoading: true, // 是否顯示loading
loadingText: '二維碼生成中', // loading文字
colorDark: "#333333", colorLight: "#FFFFFF", correctLevel: qrCode.CorrectLevel.H }) }, } </script>