十四洲 2022-09-29 09:43 采纳率: 37.5%
浏览 109
已结题

关于报错Error in v-on handler: "TypeError: Cannot read property 'personNumber' of undefined"

问题遇到的现象和发生背景

uniapp在localstroage获取数据,从registration存一个数据由login页面页来读取,实现仅前端页面的登录。但是遇见了报错问题

img

用代码块功能插入代码,请勿粘贴截图

这个是那一个部分的代码,问题应该在第二个uni.getStorage和if判断那边

denglu() {
                console.log(this.dataBase);
                //存储数据到storage
                uni.setStorageSync('root', this.dataBase)
                uni.getStorage({
                    key: 'root',
                    success: function(res) {
                        console.log(res.data);
                    }
                });
                uni.getStorage({
                    key: 'form',
                    success: function (res) {
                        console.log(res.data);
                    this.customFormData=res;
                    }
                });
                if (this.dataBase.username == this.customFormData.personNumber && this.dataBase.password ==
                    this.customFormData.password) {
                    console.log('登陆成功');
                    uni.showToast({
                        icon: 'success',
                        title: "登陆成功,请稍等"
                    });
                } else {
                    console.log('密码错误啦 ');
                    uni.showToast({
                        icon: 'error',
                        title: "账号或密码错误"
                    })
                }
            },

运行结果及报错内容

这个是错报

img

我想要达到的结果

请问如何让解决这个报错

  • 写回答

3条回答 默认 最新

  • 崽崽的谷雨 2022-09-29 10:16
    关注

    personNumber 未定义
    this.customFormData这个 里面 没有 personNumber 属性
    可以

    if((this.customFormData&&this.dataBase.username == this.customFormData.personNumber)&& this.dataBase.password ==
                        this.customFormData.password ){
                        
                    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
  • Oliver尹 前端领域优质创作者 2022-09-29 10:14
    关注

    异步问题,执行的时候没有读取完,最简单的改法,就是把执行的判断代码的实际放到回调里

        denglu() {
                console.log(this.dataBase);
                //存储数据到storage
                uni.setStorageSync('root', this.dataBase)
                uni.getStorage({
                    key: 'root',
                    success: function(res) {
                        console.log(res.data);
                    }
                });
                uni.getStorage({
                    key: 'form',
                    success: function (res) {
                        console.log(res.data);
                    this.customFormData=res;
                    if (this.dataBase.username == this.customFormData.personNumber && this.dataBase.password ==
                        this.customFormData.password) {
                        console.log('登陆成功');
                        uni.showToast({
                            icon: 'success',
                            title: "登陆成功,请稍等"
                        });
                    } else {
                        console.log('密码错误啦 ');
                        uni.showToast({
                            icon: 'error',
                            title: "账号或密码错误"
                        })
                    }
                    }
                });
             
            },
    
    
    评论
  • CSDN-Ada助手 CSDN-AI 官方账号 2022-09-29 10:11
    关注
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 10月7日
  • 已采纳回答 9月29日
  • 创建了问题 9月29日

悬赏问题

  • ¥15 我不明白为什么c#微软的官方api浏览器为什么不支持函数说明的检索,有支持检索函数说明的工具吗?
  • ¥15 ORBSLAM2框架跑ICL-NUIM数据集
  • ¥15 在我想检测ros是否成功安装时输入roscore出现以下
  • ¥30 老板让我做一个公司的投屏,实时显示日期,时间,安全生产的持续天数,完全没头绪啊
  • ¥15 Google Chrome 所有页面崩溃,三种解决方案都没有解决,我崩溃了
  • ¥20 使用uni-app发起网络请求,获取重定向302返回的cookie
  • ¥20 手机外部浏览器拉起微信小程序支付 (相关搜索:微信小程序)
  • ¥20 怎样通过一个网址找到其他同样模版的网址
  • ¥30 XIAO esp32c3 读取FDC2214的数据
  • ¥15 在工控机(Ubuntu系统)上外接USB蓝牙硬件进行蓝牙通信