在这里,我试图做一个标签栏,在其中标签的数量增加按下一个按钮。选项卡的内容保持不变。我该怎么办?
发布于 2019-11-05 06:06:54
你可以做这样的事。虽然它的反应不是反应
关于事件,增加数组的大小,然后
{this.state.tabs.map((tab,idx) => ( )将为您复制组件。
import React,{Component} from 'react';
import './App.css';
import Tabs from '@material-ui/core/Tabs';
import Tab from '@material-ui/core/Tab';
class App extends Component {
constructor(props){
super(props)
this.state={
tabs:["Tab1"],
}
}
replicate=()=>{
let tabs = this.state.tabs;
tabs.push("Tab2")
this.setState({
tabs
})
}
render() {
return (
<>
<button onClick={this.replicate}> Replicate</button>
<Tabs
value={"tabs"}
indicatorColor="primary"
textColor="primary"
// onChange={handleChange}
aria-label="disabled tabs example"
>
{/* // Here when the action is fired the array increases its size and this map replicate the tab */}
{this.state.tabs.map((tab, idx) => (
<Tab label="Active" />
))}
</Tabs>
</>
);
}
}
export default App;https://stackoverflow.com/questions/58704872
复制相似问题