宇林
宇林
  • 发布:2024-05-24 17:22
  • 更新:2024-05-29 09:30
  • 阅读:103

【报Bug】微信小程序使用uni-popup-dialog报错!!!

分类:uni-app

产品分类: uniapp/小程序/微信

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: win10

HBuilderX类型: 正式

HBuilderX版本号: 4.15

第三方开发者工具版本号: 1.06.2402040

基础库版本号: 3.4.2

项目创建方式: HBuilderX

示例代码:

<uni-popup ref="perm" type="dialog">
<uni-popup-dialog mode="base" title="提示" :content="未给与相机权限"
confirmText="前往设置" @close="permCancel" :cancelText="取消" @confirm="permConfirm">
</uni-popup-dialog>
</uni-popup>

操作步骤:

代码里面引用该组件

预期结果:

控制台不会出现错误提示

实际结果:

微信小程序控制台报错

bug描述:

使用了uni-popup-dialog组件,微信开发工具控制台报错,找到代码地方,打印结果为undefined,百分百复现

2024-05-24 17:22 负责人:无 分享
已邀请:
喜欢技术的前端

喜欢技术的前端 - QQ---445849201

照你的例子试了,写成组件,显示正常,你先排查下多语言,先改成字符串看报错不,附件有代码

  • 宇林 (作者)

    我先测试你的方案发现仍然报错,然后我尝试把组件换个地方,就不报错了,是什么原因?截图贴在下面

    2024-05-29 09:28

喜欢技术的前端

喜欢技术的前端 - QQ---445849201

改一下 属性 content cancelText

<template>  
    <view>  
        <uni-popup ref="perm" type="dialog">  
            <uni-popup-dialog mode="base" title="提示" content="未给与相机权限" confirmText="前往设置" @close="permCancel"  
                cancelText="取消" @confirm="permConfirm">  
            </uni-popup-dialog>  
        </uni-popup>  
        <button @click="btn">button</button>  
    </view>  
</template>  
<script>  
    export default {  

        methods: {  
            btn() {  
                this.$refs.perm.open()  
            },  
            permCancel(){  

            },  
            permConfirm(){  

            }  
        }  
    }  
</script>  
<style lang="scss">  

</style>
  • 宇林 (作者)

    我用的国际化,我把国际化代码删了,用的中文方便看,你的uni-popup-dialog组件是最新版本吗?微信开发工具、基础库版本和hbuilderx版本都和我一样吗?我只要使用就报错

    2024-05-25 09:05

  • 喜欢技术的前端

    回复 宇林: 是的,你可以新建个项目,用这个页面试试

    2024-05-25 23:12

  • 宇林 (作者)

    回复 宇林: 回复 喜欢技术的前端: 新建项目引用确实没问题,老哥帮忙看一下,我写的页面有没有问题,代码贴在下面

    2024-05-27 10:48

  • 宇林 (作者)

    回复 喜欢技术的前端: 下面是一个组件,我在首页引用,然后运行到小程序就报错,不知道哪里有问题。。

    2024-05-27 10:49

宇林

宇林 (作者)

<template>  
    <view>  
        <uni-popup ref="perm" type="dialog">  
            <uni-popup-dialog mode="base" :title="$t('lang.public.text_07')" :content="permissionText"  
                :confirmText="confirmText" @close="permCancel" :cancelText="cancelText" @confirm="permConfirm">  
            </uni-popup-dialog>  
        </uni-popup>  
    </view>  
</template>  

<script>  
    const app = getApp();  
    export default {  
        emits: ['permOk'],  
        data() {  
            return {  
                permissionText: '',  
                confirmText: this.$t('lang.perm.text_03'),  
                cancelText: this.$t('lang.public.text_05')  
            }  
        },  
        methods: {  
            // 确认  
            permConfirm() {  
                uni.openAppAuthorizeSetting({  
                    success() {  
                        app.globalData.openSetting = true;  
                    },  
                    fail(res) {  
                        console.log('打开系统设置失败', res)  
                    }  
                })  
            },  
            // 取消  
            permCancel() {  
                this.$refs.perm.close()  
            },  
            // 判断相机和相册权限  
            checkCameraAndAlbumPerm() {  
                let isIos = uni.getSystemInfoSync().platform == 'ios';  
                if (isIos) {  
                    var album = plus.ios.import("PHPhotoLibrary"),  
                        camera = plus.ios.import("AVCaptureDevice"),  
                        authA = album.authorizationStatus(),  
                        authC = camera.authorizationStatusForMediaType('vide');  
                    console.log('ios权限获取情况:', '相册:', authA, '相机:', authC)  
                    plus.ios.deleteObject(album);  
                    plus.ios.deleteObject(camera);  
                    if (authC != 0 && authC != 3) {  
                        this.permissionText = this.$t('lang.perm.text_01');  
                        this.cancelText = this.$t('lang.public.text_05');  
                        this.$refs.perm.open()  
                    } else if (authA != 0 && authA != 3) {  
                        this.permissionText = this.$t('lang.perm.text_02');  
                        this.cancelText = this.$t('lang.perm.text_04');  
                        this.$refs.perm.open()  
                    } else {  
                        this.$emit('permOk')  
                    }  
                } else {  
                    const perms = ['android.permission.CAMERA', 'android.permission.READ_EXTERNAL_STORAGE'];  
                    this.requestAndroidPermission(perms).then(resp => {  
                        var camera, album;  
                        for (var i = 0; i < perms.length; i++) {  
                            if (perms[0] === resp[i].name) {  
                                camera = resp[i].value;  
                            }  
                            if (perms[1] === resp[i].name) {  
                                album = resp[i].value;  
                            }  
                        }  
                        console.log('安卓权限获取情况:', '相册:', album, '相机:', camera)  
                        if (camera != 3) {  
                            this.permissionText = this.$t('lang.perm.text_01');  
                            this.cancelText = this.$t('lang.public.text_05');  
                            this.$refs.perm.open()  
                        } else if (album != 3) {  
                            this.permissionText = this.$t('lang.perm.text_02');  
                            this.cancelText = this.$t('lang.perm.text_04');  
                            this.$refs.perm.open()  
                        } else {  
                            this.$emit('permOk')  
                        }  
                    })  
                }  
            },  
            // Android权限查询  
            requestAndroidPermission(permissionIDs) {  
                return new Promise((resolve, reject) => {  
                    plus.android.requestPermissions(  
                        permissionIDs,  
                        function(obj) {  
                            var result = [];  
                            for (var i = 0; i < obj.granted.length; i++) {  
                                result.push({  
                                    name: obj.granted[i],  
                                    value: 3  
                                })  
                            }  
                            for (var i = 0; i < obj.deniedPresent.length; i++) {  
                                result.push({  
                                    name: obj.deniedPresent[i],  
                                    value: -1  
                                })  
                            }  
                            for (var i = 0; i < obj.deniedAlways.length; i++) {  
                                result.push({  
                                    name: obj.deniedAlways[i],  
                                    value: -2  
                                })  
                            }  
                            resolve(result)  
                        },  
                        function(error) {  
                            console.log('申请权限错误:' + error.code + " = " + error.message);  
                            resolve({  
                                code: error.code,  
                                message: error.message  
                            })  
                        }  
                    )  
                })  
            },  
            // 提示或等待  
            showLoadOrToast(title, type = 0, time = 1500) {  
                switch (type) {  
                    case 0:  
                        uni.showToast({  
                            title: title,  
                            icon: 'none',  
                            duration: time  
                        })  
                        break;  
                    case 1:  
                        uni.showLoading({  
                            title: title,  
                            mask: true  
                        })  
                        break;  
                }  
            }  
        }  
    }  
</script>  

<style>  
</style>
宇林

宇林 (作者)

原本组件放在component里面,引用就报错,然后换到index页面同级目录就不报错了

要回复问题请先登录注册