zouyu
2023-12-27 4e2bb29096ac63837f8d2c5e25766ee094f45d6c
src/views/common/qrCodeApp.vue
@@ -27,7 +27,7 @@
    data() {
        return {
            isShow: true,
            camera: "front",
            camera: "rear",
            result: "", // 扫码结果信息
            error: "" // 错误信息
        };
@@ -35,29 +35,26 @@
    created() { },
    methods: {
        openCamera(){
            this.camera="front"
            this.camera='rear'
        },
        //回调扫描结果
        onDecode(result) {
            console.log(result);
            if (result !== "") {
                this.result=result
                this.$emit("ok",this.result)
                this.cancelCode()
                // alert(result)
            }
        },
        // 相机反转
        switchCamera() {
            switch (this.camera) {
                //前置
                case 'front':
                    //转后置
                    this.camera = 'rear'
                    break
                    //反之
                //反之
                case 'rear':
                    this.camera = 'front'
                this.camera = 'front'
                break
                case 'front':
                    //后置
                    this.camera = 'rear'
                    break
                default:
                    this.$toast('错误')
@@ -75,12 +72,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 +98,7 @@
        }
    },
    watch: {
        "result": {
            handler(newVal) {
                console.log('扫描值' + newVal);
            },
            deep: true
        }
    }
};
</script>