<div id="app"></div>
@import 'https://fonts.googleapis.com/css?family=Share+Tech+Mono';

@import 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css';

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  width: 100vw;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: radial-gradient(#28a9dd, #0d4e77);
  font-family: "Share Tech Mono", monospace;
  font-size: 2rem;
}

.card {
    position: relative;
    backdrop-filter: blur(10px);
    background-color: rgba(255, 255, 255, 0.5);
    border-radius: 5px;
    padding:2vw;
    box-sizing: border-box;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
    transition: .3s ease;
    margin: 3vw;
}

h1 {
  position: relative;
  z-index: 1;
  border-left: 5px solid #ed2553;
  margin: 0 0 3vh -2vw;
  padding: 10px 0 10px 2vw;
  color: #ed2553;
  font-size: 32px;
  font-weight: 600;
  text-transform: uppercase;
}

p {
  font-family: "Share Tech Mono", monospace;
  margin: 1em 0;
  text-align: center;
}

input[type="text"]{
	padding: 15px;
	border: 1px solid #ccc;
	border-radius: 3px;
	margin-bottom: 10px;
	width: 100%;
	box-sizing: border-box;
	font-family: "Share Tech Mono", monospace;
	color: #2C3E50;
	font-size: 16px;
}
class App extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
            value: localStorage.getItem('userName') || '@大漠'
        }
        // 使用React生命周期来替代下面这行代码
        this.onChange = this.onChange.bind(this)
         
    }
  
    componentDidUpdate() {
        localStorage.setItem('userName', this.state.value)
    }

    onChange(e) {
        this.setState({
            value: e.target.value
        })
    }

    render() {
        return (
            <div className="card">
                <h1>使用ES6 Class创建组件(React.Component)</h1>
                <input 
                    type="text"
                    value={this.state.value}
                    onChange={this.onChange}
                />
                <p>Hello, {this.state.value} (^_^)!!!</p>
            </div>
        )
    }
}

const rootElement = document.getElementById("app");
ReactDOM.render(<App />, rootElement);
View Compiled

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/react/16.9.0/umd/react.production.min.js
  2. https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.8.6/umd/react-dom.production.min.js