技术不行但人小帅 2023-02-27 23:01 采纳率: 59.7%
浏览 28
已结题

微信云开发传值判断问题

为什么这段代码只有账号和数据库相同 时才报错, 当账号不同时不报错?

            submit() {
                this.$refs.uLogin.validate().then(res => {
                uni.$u.toast('正在登录')
                
                    this.isConfirm = false;
                    setTimeout(() => {
                        this.isConfirm = true
                        const db = wx.cloud.database()
                        let vm = this
                        db.collection('userAccounts').where({
                            user:vm.login.userInfo.user,
                            
                        }).get({
                            success: function(res) {
                                
                                if((res.data[0].password==vm.login.userInfo.password)&&(res.data[0].user==vm.login.userInfo.user)){
                                    uni.$u.toast('欢迎回家!');
                                }else{
                                    uni.$u.toast('账号或密码错误!');
                                }
                                
                            }
                        })
                        // 这里此提示会被this.start()方法中的提示覆盖
                    
                        // 通知验证码组件内部开始倒计时

                    }, 2000);
                    // this.isConfirm=false;
                }).catch(errors => {
                    this.isConfirm = false;
                    setTimeout(() => {
                        this.isConfirm = true
                        // 这里此提示会被this.start()方法中的提示覆盖
                        uni.$u.toast('账号或密码错误');
                        // 通知验证码组件内部开始倒计时

                    }, 2000);
                })
            },

  • 写回答

1条回答 默认 最新

  • 技术不行但人小帅 2023-02-28 00:16
    关注
    db.collection('userAccounts').where({
                                user:vm.login.userInfo.user,
                                password:vm.login.userInfo.password
                            }).get({
                                success: function(res) {
                                      //在这里面就算改变了this的指向也无法获取到 this.login.userinfo.user还有password值 所以一直没反应。
                                      if(res.data.length==0){
                                          uni.$u.toast('密码或账号错误')
                                      }else{
                                            uni.$u.toast('欢迎回家')
                                      }
                                       
                                }
                            })
    
    采取曲线救国的方式, 搞定
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 2月28日
  • 已采纳回答 2月28日
  • 创建了问题 2月27日

悬赏问题

  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表