片段1 import React from 'react';class App extends React.Component { constructor() { super(); this.state = { data: [] }; this.setStateHandler = this.setStateHandler.bind(this); }; setStateHandler() { var item = "设置状态..."; var myArr
import React from 'react'; class App extends React.Component { constructor() { super(); this.state = { data: [] }; this.setStateHandler = this.setStateHandler.bind(this); }; setStateHandler() { var item = "设置状态..."; var myArray = this.state.data; myArray.push(item); this.setState({data: myArray}); }; render() { return (片段2State Array: {this.state.data.join()}
); } } export default App;
import React from 'react'; class App extends React.Component { constructor() { super(); this.state = { data: [] }; }; setStateHandler() { var item = "设置状态..."; var myArray = this.state.data; myArray.push(item); this.setState({data: myArray}); }; render() { return (State Array: {this.state.data.join()}
); } } export default App;