uni-app实现扫码

主要用的就是uni.scanCode({})这个函数,
代码如下:

            scan1() {
                 let that = this;
                 // 允许从相机和相册扫码
                 uni.scanCode({
                     success: function(res) {
                         that.result1 = res.result;
                     }
                 });
             },
             scan2() {
                 let that = this;
                 // 只允许通过相机扫码
                 uni.scanCode({
                     onlyFromCamera: true,
                     success: function(res) {
                         that.result2 = res.result;
                         console.log('条码类型:' + res.scanType);
                         console.log('条码内容:' + res.result);
                     }
                 });
             },
             scan3() {
                 let that = this;
                 // 调起条码扫描
                 uni.scanCode({
                     scanType: 'barCode',
                     success: function (res) {
                         that.result3 = res.result;
                         console.log('条码类型:' + res.scanType);
                         console.log('条码内容:' + res.result);
                     }
                 });
             }
posted @ 2021-06-30 10:22  seekHelp  阅读(3474)  评论(0编辑  收藏  举报