You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.2 KiB

---
order: 3
title:
zh-CN: 切换到下一步
en-US: Switch to next
---
10 years ago
## zh-CN
9 years ago
随机生成 3~6 个步骤,初始随机进行到其中一个步骤。
10 years ago
## en-US
Let's generate 3~6 steps randomly, and proceed to a random step.
10 years ago
````jsx
import { Steps, Button } from 'antd';
const Step = Steps.Step;
const array = Array.apply(null, Array(Math.floor(Math.random() * 3) + 3));
const steps = array.map((item, i) => ({
title: `步骤${i + 1}`,
}));
10 years ago
const App = React.createClass({
10 years ago
getInitialState() {
return {
current: Math.floor(Math.random() * steps.length),
};
10 years ago
},
next() {
let current = this.state.current + 1;
if (current === steps.length) {
current = 0;
10 years ago
}
this.setState({ current });
10 years ago
},
render() {
const { current } = this.state;
return (
<div>
<div style={{ marginBottom: 24 }}>当前正在执行第 {current + 1} 步</div>
<Steps current={current}>
{steps.map((s, i) => <Step key={i} title={s.title} description={s.description} />)}
</Steps>
<div style={{ marginTop: 24 }}>
<Button onClick={this.next}>下一步</Button>
</div>
</div>
);
},
10 years ago
});
ReactDOM.render(<App />, mountNode);
10 years ago
````