我是新手,对一些基础知识做出react和挣扎。我想在按钮的 onClick 事件上显示一个表单。不知何故,我无法实现,而且我在控制台中也没有发现任何错误。有人可以指导我通过。
下面是我的 App.js
import React, { Component } from 'react';
import EnvironmentList from './components/enviromentList';
import ManageApp from './components/manageApp'
import './App.css';
class App extends Component {
state = {
Apps : [
{ AppName : "a1" },
{ AppName : "a2" },
{ AppName : "a3" },
]
}
render(){
return (
<div className="App">
<header className="App-header">
<h1>Welcome to environment Portal!</h1>
</header>
<EnvironmentList Apps={this.state.Apps}/>
<ManageApp />
</div>
);
}
}
export default App;
下面是我的 manageApp.js
import React, { Component } from 'react';
class ManageApp extends Component{
constructor(props){
super(props);
this.getForm = this.getForm.bind(this);
}
getForm = (e) => {
return (
<div>
<form id= "add-app">
<label>Application Name : </label>
<input type="text"> </input>
<label> id : </label>
<input type="text" ></input>
<label>Server details : </label>
<input ></input>
<button>Create</button>
</form>
</div>
);
}
render(){
return (
<div className='manage-app'>
<h1>Manage Application</h1>
<button onClick={ this.getForm }>Add New Application</button>
<button>Change Existing Application</button>
<button>Remove Application</button>
</div>
);
}
}
export default ManageApp;
如何通过单击“添加应用程序”按钮在浏览器中显示表单