javascript - React 组件在按钮 onClick 之后不显示在移动设备上,但在桌面上工作得很好

标签 javascript html css reactjs

我制作了一个应用程序,它呈现基本的登录表单并发送带有用户名和密码的获取请求,单击登录按钮后,会呈现另一个组件,在另一个选项卡中打开谷歌登录页面返回需要粘贴到组件中的代码。 一切在桌面上都运行良好;另一方面,在移动设备上,第二个组件不会被渲染。 我认为这可能是 CSS 的问题,但我不确定。

import React, { Component } from "react";

export default class Spaggiari extends Component {
  state = {
    username: null,
    password: ""
  };

  handleClick = () => {
    fetch(
      `http://localhost:7000/api/gviva/${this.state.username}&${this.state.password}`
    )
      .then(response => response.json())
      .then(resData => {
        //console.log(resData);
        if (resData !== "Wrong credentials") {
          //console.log("sending object returned as prop to googlecode")
          this.props.handler(resData);
          console.log("Logged in");
          console.log(resData);
        } else {
          console.log(resData);
        }
      });
  };

  updateValue = e => {
      console.log(this.state.username);
    if (e.target.name === "username") {
      this.setState({ username: e.target.value });
    } else if (e.target.name === "password") {
      this.setState({ password: e.target.value });
    }
  };

  render() {
    return (
      <div>
        <div>
          <div className="wrapper fadeInDown">
            <div id="formContent">
              {/* Tabs Titles */}
              {/* Icon */}
              <div className="fadeIn first">
                <img
                  src="https://media.spaggiari.eu/rosso/sdf/img/loghi_progetti/logo_cvv.png"
                  id="icon"
                  alt="User Icon"
                />
              </div>
              {/* Login Form */}
              <form>
                <input
                  type="text"
                  id="login"
                  className="fadeIn second"
                  name="username"
                  placeholder="Username"
                  onKeyUp={this.updateValue}
                  autoComplete="off"
                  aria-describedby="emailHelp"
                />
                <input
                  type="password"
                  id="password"
                  className="fadeIn third"
                  placeholder="Password"
                  name="password"
                  onKeyUp={this.updateValue}
                  autoComplete="off"
                />
                <input
                  type="button"
                  onClick={this.handleClick}
                  className="fadeIn fourth"
                  value="Log In"
                ></input>
              </form>
              {/* Remind Passowrd */}
              <div id="formFooter">
                <small id="emailHelp" className="form-text text-muted">
                  If you have already used this app, your events will be updated
                  and you will not need to sign-in in to your Google account
                </small>
              </div>
            </div>
          </div>
        </div>
      </div>
    );
  }
}





<!-- begin snippet: js hide: false console: true babel: false -->

/* BASIC */

html {
  background-color: #56baed;
}

body {
  font-family: "Poppins", sans-serif;
  height: 100vh;
}

a {
  color: #92badd;
  display:inline-block;
  text-decoration: none;
  font-weight: 400;
}

h2 {
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  text-transform: uppercase;
  display:inline-block;
  margin: 40px 8px 10px 8px;
  color: #cccccc;
}



/* STRUCTURE */

.wrapper {
  display: flex;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  width: 100%;
  min-height: 100%;
  padding: 20px;
}

#formContent {
  -webkit-border-radius: 10px 10px 10px 10px;
  border-radius: 10px 10px 10px 10px;
  background: #333;
  padding: 30px;
  width: 90%;
  max-width: 450px;
  position: relative;
  padding: 0px;
  -webkit-box-shadow: 0 30px 60px 0 rgba(0,0,0,0.3);
  box-shadow: 0 30px 60px 0 rgba(0,0,0,0.3);
  text-align: center;
}

#formFooter {
  background-color: #f6f6f6;
  border-top: 1px solid #dce8f1;
  padding: 25px;
  text-align: center;
  -webkit-border-radius: 0 0 10px 10px;
  border-radius: 0 0 10px 10px;
}



/* TABS */

h2.inactive {
  color: #cccccc;
}

h2.active {
  color: #0d0d0d;
  border-bottom: 2px solid #5fbae9;
}


/* FORM TYPOGRAPHY*/

input[type=button], input[type=submit], input[type=reset]  {
  background-color: #56baed;
  border: none;
  color: white;
  padding: 15px 80px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  text-transform: uppercase;
  font-size: 13px;
  -webkit-box-shadow: 0 10px 30px 0 rgba(95,186,233,0.4);
  box-shadow: 0 10px 30px 0 rgba(95,186,233,0.4);
  -webkit-border-radius: 5px 5px 5px 5px;
  border-radius: 5px 5px 5px 5px;
  margin: 5px 20px 40px 20px;
  -webkit-transition: all 0.3s ease-in-out;
  -moz-transition: all 0.3s ease-in-out;
  -ms-transition: all 0.3s ease-in-out;
  -o-transition: all 0.3s ease-in-out;
  transition: all 0.3s ease-in-out;
}

input[type=button]:hover, input[type=submit]:hover, input[type=reset]:hover  {
  background-color: #39ace7;
}

input[type=button]:active, input[type=submit]:active, input[type=reset]:active  {
  -moz-transform: scale(0.95);
  -webkit-transform: scale(0.95);
  -o-transform: scale(0.95);
  -ms-transform: scale(0.95);
  transform: scale(0.95);
}

input[type=text], input[type=password]{
  background-color: #f6f6f6;
  border: none;
  color: #0d0d0d;
  padding: 15px 32px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 16px;
  margin: 5px;
  width: 85%;
  border: 2px solid #f6f6f6;
  -webkit-transition: all 0.5s ease-in-out;
  -moz-transition: all 0.5s ease-in-out;
  -ms-transition: all 0.5s ease-in-out;
  -o-transition: all 0.5s ease-in-out;
  transition: all 0.5s ease-in-out;
  -webkit-border-radius: 5px 5px 5px 5px;
  border-radius: 5px 5px 5px 5px;
}

input[type=text]:focus {
  background-color: #fff;
  border-bottom: 2px solid #5fbae9;
}

input[type=text]:placeholder {
  color: #cccccc;
}



/* ANIMATIONS */

/* Simple CSS3 Fade-in-down Animation */
.fadeInDown {
  -webkit-animation-name: fadeInDown;
  animation-name: fadeInDown;
  -webkit-animation-duration: 1s;
  animation-duration: 1s;
  -webkit-animation-fill-mode: both;
  animation-fill-mode: both;
}

@-webkit-keyframes fadeInDown {
  0% {
    opacity: 0;
    -webkit-transform: translate3d(0, -100%, 0);
    transform: translate3d(0, -100%, 0);
  }
  100% {
    opacity: 1;
    -webkit-transform: none;
    transform: none;
  }
}

@keyframes fadeInDown {
  0% {
    opacity: 0;
    -webkit-transform: translate3d(0, -100%, 0);
    transform: translate3d(0, -100%, 0);
  }
  100% {
    opacity: 1;
    -webkit-transform: none;
    transform: none;
  }
}

/* Simple CSS3 Fade-in Animation */
@-webkit-keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
@-moz-keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }

.fadeIn {
  opacity:0;
  -webkit-animation:fadeIn ease-in 1;
  -moz-animation:fadeIn ease-in 1;
  animation:fadeIn ease-in 1;

  -webkit-animation-fill-mode:forwards;
  -moz-animation-fill-mode:forwards;
  animation-fill-mode:forwards;

  -webkit-animation-duration:1s;
  -moz-animation-duration:1s;
  animation-duration:1s;
}

.fadeIn.first {
  -webkit-animation-delay: 0.4s;
  -moz-animation-delay: 0.4s;
  animation-delay: 0.4s;
}

.fadeIn.second {
  -webkit-animation-delay: 0.6s;
  -moz-animation-delay: 0.6s;
  animation-delay: 0.6s;
}

.fadeIn.third {
  -webkit-animation-delay: 0.8s;
  -moz-animation-delay: 0.8s;
  animation-delay: 0.8s;
}

.fadeIn.fourth {
  -webkit-animation-delay: 1s;
  -moz-animation-delay: 1s;
  animation-delay: 1s;
}

/* Simple CSS3 Fade-in Animation */
.underlineHover:after {
  display: block;
  left: 0;
  bottom: -10px;
  width: 0;
  height: 2px;
  background-color: #56baed;
  content: "";
  transition: width 0.2s;
}

.underlineHover:hover {
  color: #0d0d0d;
}

.underlineHover:hover:after{
  width: 100%;
}



/* OTHERS */

*:focus {
    outline: none;
}

#icon {
  width:60%;
}

最佳答案

强文字: 你是对的,你的 CSS 当前不起作用,请覆盖按钮的 CSS 和包装器。

关于javascript - React 组件在按钮 onClick 之后不显示在移动设备上,但在桌面上工作得很好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60552594/

相关文章:

javascript - 从javascript中的链接获取文本

javascript - Dojo 堆叠柱形图在堆叠顶部添加总堆叠值时出现问题

javascript - 点击事件 : divs appear one at a time

html - 需要一个全屏背景图像来包含超链接

php - 将一个 Div 包裹在两个 Div 周围,这是一个使用 PHP 的 Wordpress 函数

javascript - Crocodoc 文档字体在移动设备上太小

JavaScript:在 hashchange 上按名称调用函数

javascript - 下拉选择框选项在 chrome 浏览器中不起作用

javascript - 向没有类的元素添加类 - jQuery

php - 如何将php脚本放入php脚本中的html脚本中