Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 当我git submit时,ReactJs handle submit api调用被取消_Javascript_Node.js_Reactjs_Axios - Fatal编程技术网

Javascript 当我git submit时,ReactJs handle submit api调用被取消

Javascript 当我git submit时,ReactJs handle submit api调用被取消,javascript,node.js,reactjs,axios,Javascript,Node.js,Reactjs,Axios,当我点击Login时,它向后端发送一个请求,在后端显示成功,但在react应用程序中显示取消。为什么不确定它正在发生呢。这是我的密码 [检查过程中的API请求][1] 我尝试了另一种方法,但仍然没有成功。有人能告诉我哪里弄错了吗?我在这里可能犯了什么错误 import React, { useState } from "react"; import { Link, Redirect } from "react-router-dom"; import axi

当我点击Login时,它向后端发送一个请求,在后端显示成功,但在react应用程序中显示取消。为什么不确定它正在发生呢。这是我的密码

[检查过程中的API请求][1]

我尝试了另一种方法,但仍然没有成功。有人能告诉我哪里弄错了吗?我在这里可能犯了什么错误

import React, { useState } from "react";
import { Link, Redirect } from "react-router-dom";
import axios from "axios";

export default function Login() {
  const [email, setEmail] = useState("");
  const [password, setPassword] = useState("");
  const [read, dataFetched] = useState("");

  const handleSubmit = async () => {
    const options = {
      headers: {
        "Content-Type": "application/json"
      }
    };
    return await axios.post(
      "http://localhost:3005/v1/auth/login",
      {
        email: email,
        password: password
      },
      options
    );
  };
  //console.log(read)
  return (
    <>
      <div className="container mx-auto px-4 h-full">
        <div className="flex content-center items-center justify-center h-full">
          <div className="w-full lg:w-4/12 px-4">
            <div className="relative flex flex-col min-w-0 break-words w-full mb-6 shadow-lg rounded-lg bg-blueGray-200 border-0">
              <div className="rounded-t mb-0 px-6 py-6">
                <div className="text-center mb-3">
                  <h6 className="text-blueGray-500 text-sm font-bold">
                    Sign in with
                  </h6>
                </div>
                <div className="btn-wrapper text-center">
                  <button
                    className="bg-white active:bg-blueGray-50 text-blueGray-700 font-normal px-4 py-2 rounded outline-none focus:outline-none mr-2 mb-1 uppercase shadow hover:shadow-md inline-flex items-center font-bold text-xs ease-linear transition-all duration-150"
                    type="button"
                  >
                    Github
                  </button>
                  <button
                    className="bg-white active:bg-blueGray-50 text-blueGray-700 font-normal px-4 py-2 rounded outline-none focus:outline-none mr-1 mb-1 uppercase shadow hover:shadow-md inline-flex items-center font-bold text-xs ease-linear transition-all duration-150"
                    type="button"
                  >
                    Google
                  </button>
                </div>
                <hr className="mt-6 border-b-1 border-blueGray-300" />
              </div>
              <div className="flex-auto px-4 lg:px-10 py-10 pt-0">
                <div className="text-blueGray-400 text-center mb-3 font-bold">
                  <small>Or sign in with credentials</small>
                </div>
                <form onSubmit={handleSubmit}>
                  <div className="relative w-full mb-3">
                    <label
                      className="block uppercase text-blueGray-600 text-xs font-bold mb-2"
                      htmlFor="grid-password"
                    >
                      Email
                    </label>
                    <input
                      value={email}
                      onChange={(e) => setEmail(e.target.value)}
                      type="email"
                      className="border-0 px-3 py-3 placeholder-blueGray-300 text-blueGray-600 bg-white rounded text-sm shadow focus:outline-none focus:ring w-full ease-linear transition-all duration-150"
                      placeholder="Email"
                    />
                  </div>

                  <div className="relative w-full mb-3">
                    <label
                      className="block uppercase text-blueGray-600 text-xs font-bold mb-2"
                      htmlFor="grid-password"
                    >
                      Password
                    </label>
                    <input
                      type="password"
                      value={password}
                      onChange={(e) => setPassword(e.target.value)}
                      className="border-0 px-3 py-3 placeholder-blueGray-300 text-blueGray-600 bg-white rounded text-sm shadow focus:outline-none focus:ring w-full ease-linear transition-all duration-150"
                      placeholder="Password"
                    />
                  </div>
                  <div>
                    <label className="inline-flex items-center cursor-pointer">
                      <input
                        id="customCheckLogin"
                        type="checkbox"
                        className="form-checkbox border-0 rounded text-blueGray-700 ml-1 w-5 h-5 ease-linear transition-all duration-150"
                      />
                      <span className="ml-2 text-sm font-semibold text-blueGray-600">
                        Remember me
                      </span>
                    </label>
                  </div>

                  <div className="text-center mt-6">
                    <button
                      className="bg-blueGray-800 text-white active:bg-blueGray-600 text-sm font-bold uppercase px-6 py-3 rounded shadow hover:shadow-lg outline-none focus:outline-none mr-1 mb-1 w-full ease-linear transition-all duration-150"
                      type="submit"
                    >
                      Sign In
                    </button>
                  </div>
                </form>
              </div>
            </div>
            <div className="flex flex-wrap mt-6 relative">
              <div className="w-1/2">
                <a
                  href="#pablo"
                  onClick={(e) => e.preventDefault()}
                  className="text-blueGray-200"
                >
                  <small>Forgot password?</small>
                </a>
              </div>
              <div className="w-1/2 text-right"></div>
            </div>
          </div>
        </div>
      </div>
    </>
  );
}
import React,{useState}来自“React”;
从“react router dom”导入{Link,Redirect};
从“axios”导入axios;
导出默认函数登录(){
const[email,setEmail]=useState(“”);
const[password,setPassword]=useState(“”);
const[read,dataFetched]=useState(“”);
const handleSubmit=async()=>{
常量选项={
标题:{
“内容类型”:“应用程序/json”
}
};
返回等待axios.post(
"http://localhost:3005/v1/auth/login",
{
电邮:电邮,,
密码:密码
},
选择权
);
};
//console.log(读取)
返回(
登录
github
谷歌

密码 setPassword(e.target.value)} className=“border-0 px-3 py-3占位符-blueGray-300 text-blueGray-600 bg白色圆形文本sm阴影焦点:轮廓无焦点:环形w-完全轻松线性过渡所有持续时间-150” 占位符=“密码” /> 记得我吗 登录 ); }
能 [1] :