Dino_Xie
Dino_Xie
  • 发布:2017-07-26 18:07
  • 更新:2020-04-22 13:58
  • 阅读:19068

vue-cli 上用barcode调用摄像头扫码二维码,调用self.scan.start()就出现app强退的情况,如何解决?

分类:HTML5+
        plusReady () {  
            const self = this  
            // 获取窗口               
            self.scan = new plus.barcode.Barcode('code');  
            self.scan.onmarked = self.onmarked;  
        },  
        sweep () {  
            const self = this  
            self.scan.start();  
        },  
        onmarked (type, result) {  
            var text = '未知: ';  

            switch (type) {  
                case plus.barcode.QR:  
                type = 'QR';  
                break;  
                case plus.barcode.EAN13:  
                type = 'EAN13';  
                break;  
                case plus.barcode.EAN8:  
                type = 'EAN8';  
                break;  
                default:  
                type = '其他'+type  
                break;  
            }  

            result = result.replace(/\n/g, '')  

            if (result.indexOf('http://') == 0 || result.indexOf('https://') == 0) {  
                plus.nativeUI.confirm(result, function(i){  
                    if(i.index == 0) {  
                        self.back(); //返回上个页面  
                        plus.runtime.openURL(result);  
                    } else {  
                        self.back(); //返回上个页面  
                    }  
                }, '',['打开','取消']);  
            } else {  
                self.back(); //返回上个页面  
                plus.nativeUI.alert(result)  
            }  
        }  
    },  
    mounted () {  
        const self = this  
        if(window.plus) {  
            self.plusReady()  
        } else {  
            document.addEventListener('plusready', self.plusReady, false);  
        }  

        document.addEventListener('DOMContentLoaded', function() {  
            alert('DOMLoaded')  
            self.domready = true;  
            self.plusReady()  
        }, false)  

    }  

HTML部分:
<div id="code">
<div style="width:14rem;height:14rem; background-color: #fff; margin: 15% auto 5%; text-align: center"></div>
<p class="tip" style="text-align: center">...载入中...</p>
</div>
<p>将二维码放入框内,即可自动扫描</p>
<div class="sweep" @click="sweep">开始扫码</div>

2017-07-26 18:07 负责人:无 分享
已邀请:
格创网络

格创网络 - 专业小程序、APP开发。

真机测试没问题,打包后一扫就闪退了,不知道啥原因。

Dino_Xie

Dino_Xie (作者) - 90后

已解决:
因为行内样式(有点奇葩),把所在容器的行内样式删除就可以了。

  • dengs

    请问如何配置 我用VUE 做扫一扫功能实现不了

    2017-10-06 08:57

  • 风剑苍月

    请问上面那段代码是写在methods里面吗

    2018-04-03 16:42

  • 6***@qq.com

    回复 dengs:https://github.com/tyaqing/mogo-h5plus

    2018-06-11 09:12

dengs

dengs

有没有DEMO 可以参考下的

  • 6***@qq.com

    https://github.com/tyaqing/mogo-h5plus

    2018-06-11 09:12

l***@126.com

l***@126.com

同求demo

  • 6***@qq.com

    https://github.com/tyaqing/mogo-h5plus

    2018-06-11 09:12

爱地球的Lan

爱地球的Lan

大佬 求demo 13612914754@163.com

6***@qq.com

6***@qq.com

vue的脚手架 https://github.com/tyaqing/mogo-h5plus

prettydog

prettydog

请问有没有什么东西可以存储token的?

l***@126.com

l***@126.com

必须要生成APP后才能使用吗?用网页打开提示 puls is not defined

该问题目前已经被锁定, 无法添加新回复