为什么账号密码在测试中是对的返回200了,但是浏览器上返回401呢

login(userForm) {
      this.$refs["userForm"].validate((valid) => {
        if (valid) {
          console.log("userform");
          console.log(this.userForm);
          // 表单校验合法
          // 这是参数一和参数二
          // this.$axios.post("/api/backend/login", this.userForm)
          // 这种你需要指定method
          // this.$axios({
          //   method: 'post',
          //   url: '/api/backend/login',
          //   data: this.userForm
          // })
          // 这种是错的
          // axios.post(url[, data[, config]])
          this.$axios
            .post("/api/backend/login", 
              // data: JSON.stringify(this.userForm),
              this.userForm,
              // contentType: 'application/json;charset=UTF-8'
            )
            .then((res) => {
              // console.log(username + password);
              console.log("5");
              console.log(res);
              if (res.code === "200") {
                // localStorage.setItem("user", JSON.stringify(res.data)); // 存储用户信息到浏览器
                // localStorage.setItem("menus", JSON.stringify(res.data.menus)); // 存储用户信息到浏览器
                // 动态设置当前用户的路由
                // setRoutes();
                console.log("登录成功");
                // this.$message.success("登录成功");
                // localStorage.setItem("user_id", id);
                // if (res.data.role === "ROLE_STUDENT") {
                //   this.$router.push("/PageTable");
                // } else {
                //   this.$router.push("/");
                // }
              } else if (res.code === "1005") {
                console.log("6");
                this.$message.error(res.msg);
              }
            })
            .catch((err) => {
              console.log(err);
              console.log("登陆失败");
              if (err.code === "1005") {
                console.log("6");
              }
            });
          console.log("7");
        }
      });
    },
  },

img

img

img

可以看一下你测试时发的url以及header和你在浏览器时network里边的的url和header吗,比较一下,看看是不是url或header有不同