apipost接口200状态码,浏览器控制台500状态码

后端 url

登录login方法

复制代码
login(){
        this.$refs.loginForm.validate(async valid => {
          if (!valid) return
          // 由于data属性是一个json对象,需要进行解构赋值{data:result},进行状态码判断
          const {data: result} = await this.$http.post('/api/doLogin',this.loginForm)  // 填写的表单数据都保存在表单数据loginForm对象里
          console.log('后端data数据内容',result)
          if (result.status !== 200) {
            return console.log('登录失败')
          }
          //先打印到浏览器控制台,看结果
          console.log('登录成功')
          this.$router.push('/home')
        })
      }

导致这个问题的原因 是前端没有携带 用户和密码这两个参数,

需要使用qs库 将对象序列为字符串 或将字符串转换为对象

安装 qs 库

yarn add qs 或 npm install qs

引入qs

复制代码
import qs from 'qs'
login(){
        const that = this
        this.$refs.loginForm.validate(async valid => {
          if (!valid) return
          // 将loginForm对象转换为查询字符串
          var data = qs.stringify(this.loginForm)
          // 由于data属性是一个json对象,需要进行解构赋值{data:result},进行状态码判断
           await this.$http.post('/api/doLogin',data).then(function (response){
            if (response.data.status === 200){
             console.log('登录成功')
              // ElMessage({message: '登录成功',type: 'success'})
              that.$router.push('/home')
            }else {
              console.log(response.data.status)
              console.log('api后端接口状态')
            }
          })

        })
      }
相关推荐
IT_陈寒7 小时前
Vite打包时的静态资源坑,我帮你踩过了
前端·人工智能·后端
kyle~7 小时前
C++_STL---迭代器失效
开发语言·c++
Brilliantwxx8 小时前
【C语言】 初入嵌入式C语言复习(基础+进阶面试题)
c语言·开发语言
熊野君9 小时前
附录与 Codex 实操手册
开发语言·人工智能·产品经理
默_笙9 小时前
🔥 让 AI 帮我写完整个 Next.js 博客:框架就是 AI 的"上下文 buff"
前端·javascript
牧艺9 小时前
登录页还在用渐变?我一口气做了 5 个能摸的背景动效:吹蒲公英、滴墨染水、点熔岩闷裂
前端·canvas·交互设计
陆枫Larry9 小时前
状态机简介
前端
陆枫Larry10 小时前
一次登录问题排查:接口没错,错的是旧业务逻辑
前端
小小小小宇10 小时前
大模型打分与采样原理,以及 Pi Agent 核心原理
前端
XZ-07000110 小时前
week2-1-可视化
开发语言·python