單向資料繫結
1.在constructor裡註冊資料
constructor()進行資料繫結
雙向資料繫結
1.在constructor裡用this.state註冊資料
constructor(){
super();
this.state={
user:"",
pass:"",
loginsuccess:false
2.使用onchange事件監聽資料變化並賦值給this.state
handechange(item,event){
for(let stateitem in this.state){
if(item===stateitem){
this.state[item]=event.target.value;
this.setstate(this.state)
使用者名稱 密碼
最後,貼出最終**
import '../login/login.css';
import './register.css';
class register extends component{
constructor(){
super();
this.title="註冊"
this.state={
user:"",
pass:"",
loginsuccess:false
handechange(item,event){
for(let stateitem in this.state){
if(item===stateitem){
this.state[item]=event.target.value;
this.setstate(this.state)
render(){
return (
使用者名稱 密碼
註冊
export default register;
React 雙向資料繫結
需求 我在子元件中的input框輸入內容的時候,我需要文字中指定的name內容也跟著改變 子元件 import react from react const person props export default person 父元件 import react,from react import f...
React 事件繫結
一 class方式定義元件事件繫結的幾種方法 一 在建構函式中使用bind繫結this 1 class button extends react.component 6handleclick 9render 12click me 1314 15 16 二 在呼叫的時候使用bind去繫結this 1 ...
React 事件繫結
一 class方式定義元件事件繫結的幾種方法 一 在建構函式中使用bind繫結this 1 class button extends react.component 6handleclick 9render 12click me 1314 15 16 二 在呼叫的時候使用bind去繫結this 1 ...