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

关于报错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 ){
                        
                    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

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

悬赏问题

  • ¥15 对于这个问题的代码运行
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败