王震
2023-12-22 bf8f755535e07b59116fced6dab7e2b53e78ff50
src/views/common/qrCodeApp.vue
@@ -18,8 +18,6 @@
    </div>
</template>
<script>
// 下载插件
// cnpm install --save  vue-qrcode-reader
// 引入
import { QrcodeStream } from "vue-qrcode-reader";
export default {
@@ -37,14 +35,14 @@
    created() { },
    methods: {
        openCamera(){
            this.camera="front"
            this.camera="rear"
        },
        //回调扫描结果
        onDecode(result) {
            console.log(result);
            if (result !== "") {
                this.$emit("onDecode", result);
                alert(result)
                this.result=result
                this.$emit("ok",this.result)
                this.cancelCode()
            }
        },
        // 相机反转
@@ -52,7 +50,7 @@
            switch (this.camera) {
                //前置
                case 'front':
                    //转
                    //转后置
                    this.camera = 'rear'
                    break
                    //反之
@@ -75,12 +73,7 @@
        async onInit(promise) {
            try {
                const { capabilities } = await promise;
                console.log(
                    "🚀 ~ file: cameracomponent.vue:47 ~ onInit ~ capabilities",
                    capabilities
                );
            } catch (error) {
                // console.log()
                this.$toast(error.name);
                if (error.name === "NotAllowedError") {
                    this.error = "ERROR: 您需要授予相机访问权限";
@@ -106,12 +99,7 @@
        }
    },
    watch: {
        "result": {
            handler(newVal) {
                console.log('扫描值' + newVal);
            },
            deep: true
        }
    }
};
</script>